fork download
  1. // C++ code to demonstrate printing
  2. // pattern of numbers
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. // Function to demonstrate printing
  7. // pattern
  8. void numpat(int n)
  9. {
  10. // initializing starting number
  11. int num = 1;
  12.  
  13. // Outer loop to handle number of rows
  14. // n in this case
  15. for (int i = 0; i < n; i++) {
  16.  
  17. // Inner loop to handle number of columns
  18. // values changing acc. to outer loop
  19. for (int j = 0; j <= i; j++)
  20. cout << num << " ";
  21.  
  22. // Incrementing number at each column
  23. num = num + 1;
  24.  
  25. // Ending line after each row
  26. cout << endl;
  27. }
  28. }
  29.  
  30. // Driver Code
  31. int main()
  32. {
  33. int n = 5;
  34.  
  35. // Function Call
  36. numpat(n);
  37. return 0;
  38. }
  39.  
  40.  
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5