C++ Program to Print All Numbers From 1 to n Divisible by m using While Loop
Write C++ Program to Print All Numbers From 1 to n Divisible by m using While Loop
// CPP Program to Print All Numbers From 1 to n Divisible by m using While Loop
#include <iostream>
using namespace std;
int main()
{
int n, m;
cout << "Enter n :--> ";
cin >> n;
cout << "Enter m :--> ";
cin >> m;
cout << "The divisible numbers between 1 to " << n << " by " << m << " :--> ";
int i = 1;
while(i < n)
{
if(i % m == 0)
{
cout << i << " ";
}
i++;
}
return 0;
}
Output:
Enter n :--> 24
Enter m :--> 4
The divisible numbers between 1 to 24 by 4 :--> 4 8 12 16 20