In: Computer Science
Write a C++ code using while loop which is getting the two integers from the user, and output how many numbers are multiples of 5, and how many numbers are multiples of 7 between the two integers (inclusive).
C++ code:
#include <iostream>
using namespace std;
int main(){
//initializing limits n1 and n2
int n1,n2;
//asking for them
cout<<"Enter limits: ";
//accepting them
cin>>n1>>n2;
//initializing i and count
int i=n1,count5=0,count7=0;
//looping till n2
while(i<=n2){
//checking if divisible
by 7
if(i%7==0)
//incrementing
count7
count7++;
//checking if divisible
by 5
if(i%5==0)
//incrementing
count5
count5++;
//incrementing i
i++;
}
//printing Count5
cout<<"Count of number divivsible by 5:
"<<count5<<endl;
//printing Count7
cout<<"Count of number divivsible by 7:
"<<count7<<endl;
return 0;
}
Screenshot:
Input and Output: