fork download
  1. #include <stdio.h>
  2. #include <stdlib.h> // for abs()
  3.  
  4. int main()
  5. {
  6. int num, i, y;
  7.  
  8. printf("Enter a number for generating the pyramid:\n");
  9. scanf("%d", &num);
  10.  
  11. for (y = 0; y <= num; y++)
  12. {
  13. // print spaces
  14. for (i = 0; i < num - y; i++)
  15. {
  16. printf(" ");
  17. }
  18.  
  19. // print numbers
  20. for (i = -y; i <= y; i++)
  21. {
  22. printf("%3d", abs(i));
  23. }
  24.  
  25. printf("\n");
  26. }
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Enter a number for generating the pyramid:
  0