Advertisement
llvlleo1810

Dạng bài tập về vẽ hình bằng số

Apr 17th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. Viết chương trình nhập vào n và in ra hình theo quy luật
  2. INPUT
  3. 5
  4. OUTPUT
  5. 1 2 3 4 5
  6. 2 1 2 3 4
  7. 3 2 1 2 3
  8. 4 3 2 1 2
  9. 5 4 3 2 1
  10. ------------------
  11. #include <stdio.h>
  12.  
  13. int main()
  14. {
  15.     int n;
  16.     scanf("%d", &n);
  17.     for (int i = 1; i <= n; i++) {
  18.         for (int j = i; j > 0; j--) {
  19.             printf("%d ", j);
  20.         }
  21.         for (int j = 2; j <= n - i + 1; j++) {
  22.             printf("%d ", j);
  23.         }
  24.         printf("\n");
  25.     }
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement