Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. bool IsDigit(char ch) {
  4.     return '0' <= ch && ch <= '9';
  5. }
  6.  
  7. int main() {
  8.     printf("length: ");
  9.     int len = 0;
  10.     char ch;
  11.     while ((ch = getchar()) != '\n') {
  12.         if (IsDigit(ch) && len <= 55) {
  13.             len = len * 10 + ch - '0';
  14.         }
  15.         else {
  16.             printf("error\n"); return 1;
  17.         }
  18.     }
  19.  
  20.     if (len < 1 || len > 55) {
  21.         printf("error\n"); return 1;
  22.     }
  23.  
  24.     printf("char: ");
  25.     ch = getchar();
  26.  
  27.     if (ch == '\n' || getchar() != '\n') {
  28.         printf("error\n"); return 1;
  29.     }
  30.  
  31.     for (int i = 0; i < 25; ++i) {
  32.         for (int j = 0; j < i; ++j) {
  33.             putchar(' ');
  34.         }
  35.         for (int j = 0; j < len; ++j) {
  36.             putchar(ch);
  37.         }
  38.         putchar('\n');
  39.     }
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement