#include <iostream> using namespace std; int main(){ int i, j, n; // read n from the user cin >> n; // go through pairs of a,b <= n and // print out those that divide each other for (i=1; i<=n; i++) for (j=1; j<=n; j++) if (i%j == 0) cout << i << " is divisible by " << j << endl; return 0;}
5
1 is divisible by 1 2 is divisible by 1 2 is divisible by 2 3 is divisible by 1 3 is divisible by 3 4 is divisible by 1 4 is divisible by 2 4 is divisible by 4 5 is divisible by 1 5 is divisible by 5
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!