In: Computer Science
Required program in C++ -->
#include<iostream>
using namespace std;
int main(){
int count1=0,count2=0; //declare variables count1 and count2 with
0
cout<<"Numbers divisible by 7: "; //print numbers divisible
by 7 :
for(int i=1; i<=1000; i++){ //for loop to count numbers
divisible by 7 from 1 to 1000
if(i%7==0){ //if i is perfectly divisible by 7
cout<<i<<", "; //then print i
count1++; //increase count1 by 1
}
}
cout<<endl; //change the line
cout<<"Total count of numbers divisible by 7 are:
"<<count1<<endl; //print value of count1
cout<<"Numbers with total of 7 are: "; //print numbers with
total of 7 are
for(int j=1;j<=1000;j++){ //for loop to find the numbers whose
sum is 7 from 1 to 1000
int sum=0,m; //declare variables in integer data type
int n=j; //assign the value of j to n
while(n>0){ //while loop will run till n is greater than 0
m=n%10; //remainder when n is divided by 10 is stored in m
sum=sum+m; // m is then added in sum
n=n/10; // n is then divided by 10, and its integer value is stored
in n
}
if(sum==7){ //if sum value is equal to 7
cout<<j<<", "; //print value of j
count2++; //increase count2 by 1
}
}
cout<<endl; //change the line
cout<<"Total count of numbers whose sum is 7 are:
"<<count2<<endl; //print the value of count2
}