fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int i, j, n;
  8.  
  9. // read n from the user
  10.  
  11. cin >> n;
  12.  
  13. // go through pairs of a,b <= n and
  14. // print out those that divide each other
  15.  
  16. for (i=1; i<=n; i++)
  17. for (j=1; j<=n; j++)
  18. if (i%j == 0)
  19. cout << i << " is divisible by " << j << endl;
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 2684KB
stdin
5
stdout
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