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. // print out all pairs of natural numbers
  14. // a,b <= n, such that a<b
  15.  
  16. for (i=1; i<n; i++)
  17. for (j=i+1; j<=n; j++)
  18. cout << i << " " << j << endl;
  19.  
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 2728KB
stdin
5
stdout
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5