fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int n;// 12345
  5. // 12 45
  6. // 1 5
  7. printf("Enter the number of rows: \n");
  8. scanf("%d",&n);
  9.  
  10. int nsc=n-1;
  11. int nsp=1;
  12.  
  13. for(int r=1;r<=2*n-1;r++)// first line
  14.  
  15. printf("%d",r);
  16. printf("\n");
  17.  
  18. for(int i=1;i<=n;i++){
  19. int a=1;
  20. for(int j=1;j<=nsc;j++){
  21. printf("%d",a);
  22. a++;
  23. }
  24. for(int k=1;k<=nsp;k++){
  25. printf(" ");
  26. a++;
  27. }
  28. for(int x=1;x<=nsc;x++){
  29. printf("%d",a);
  30. a++;
  31. }
  32. nsc--;
  33. nsp+=2;
  34. printf("\n");
  35. }
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0.01s 5288KB
stdin
5
stdout
Enter the number of rows: 
123456789
1234 6789
123   789
12     89
1       9