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. // and are not equal and division is not by 1
  16.  
  17. for (i=1; i<=n; i++)
  18. for (j=2; j<=n; j++)
  19. if ((i!=j) && (i%j == 0))
  20. cout << i << " is divisible by " << j << endl;
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 2684KB
stdin
5
stdout
4 is divisible by 2