fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int N=5;
  5. // 检查N的范围
  6. if (N > 0 && N < 10) {
  7. // 外层循环控制行数
  8. for (int i = 1; i <= N; i++) {
  9. // 打印空格对齐
  10. for (int j = 0; j < N - i; j++) {
  11. printf(" ");
  12. }
  13. // 打印数字
  14. for (int x = 0; x < i; x++) {
  15. printf("%d ", i);
  16. }
  17. // 换行
  18. printf("\n");
  19. }
  20. } else {
  21. printf("输入的值不在1到9之间!\n");
  22. }
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
    1 
   2 2 
  3 3 3 
 4 4 4 4 
5 5 5 5 5