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