fork download
  1. /* Write a program to take n as input and print 1 to n in the following order.
  2.  * 1
  3.  * 1 2
  4.  * 1 2 3
  5.  * 1 2 3 4
  6.  * 1 2 3 4 n
  7.  */
  8.  
  9. #include <stdio.h>
  10.  
  11. int main() {
  12. int n = 5;
  13. //scanf("%d", &n);
  14.  
  15. int i = 1, count = 1;
  16.  
  17. while (i <= n) {
  18. printf("%d ", count);
  19.  
  20. if (count == i) { // end of current line
  21. printf("\n");
  22. i++; // move to next line
  23. count = 1; // restart from 1
  24. } else {
  25. count++; // continue same line
  26. }
  27. }
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5