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