fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7. cout.tie(nullptr);
  8.  
  9. int n;
  10. cin >> n;
  11.  
  12. int cnt = 0;
  13.  
  14. for (int i = 1; i <= n; ++i) {
  15. cout << "i = " << i << ": ";
  16.  
  17. for (int j = 1; j <= i; ++j) {
  18. cout << "*";
  19. cnt++;
  20. }
  21.  
  22. cout << " (j ran " << i << " times)\n";
  23. }
  24.  
  25. cout << "\nTotal iterations = " << cnt << " (O(n^2))\n";
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.01s 5320KB
stdin
5
stdout
i = 1: * (j ran 1 times)
i = 2: ** (j ran 2 times)
i = 3: *** (j ran 3 times)
i = 4: **** (j ran 4 times)
i = 5: ***** (j ran 5 times)

Total iterations = 15 (O(n^2))