fork download
  1. #include <stdio.h>
  2. int main()
  3. {
  4. int i, space, rows, k=0, count = 0, count1 = 0;
  5.  
  6. printf("行数: ");
  7. scanf("%d",&rows);
  8.  
  9. for(i=1; i<=rows; ++i)
  10. {
  11. for(space=1; space <= rows-i; ++space)
  12. {
  13. printf(" ");
  14. ++count;
  15. }
  16.  
  17. while(k != 2*i-1)
  18. {
  19. if (count <= rows-1)
  20. {
  21. printf("%d ", i+k);
  22. ++count;
  23. }
  24. else
  25. {
  26. ++count1;
  27. printf("%d ", (i+k-2*count1));
  28. }
  29. ++k;
  30. }
  31. count1 = count = k = 0;
  32.  
  33. printf("\n");
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0s 10320KB
stdin
5
stdout
行数:         1 
      2 3 2 
    3 4 5 4 3 
  4 5 6 7 6 5 4 
5 6 7 8 9 8 7 6 5