Advertisement
dmilicev

pyramid of characters v1.c

Sep 29th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. /*
  2. C program to print following character pyramid:
  3. Enter number of lines: 5
  4.  
  5.  ABCDEFGFEDCBA
  6.  ABCDE   EDCBA
  7.  ABCD     DCBA
  8.  ABC       CBA
  9.  AB         BA
  10.  A           A
  11.  
  12. Enter number of lines: 7
  13.  
  14.  ABCDEFGHIHGFEDCBA
  15.  ABCDEFG   GFEDCBA
  16.  ABCDEF     FEDCBA
  17.  ABCDE       EDCBA
  18.  ABCD         DCBA
  19.  ABC           CBA
  20.  AB             BA
  21.  A               A
  22.  
  23. */
  24.  
  25. #include<stdio.h>
  26.  
  27. int main()
  28. {
  29.   int i,j,k,n;
  30.   char ch;
  31.  
  32. // enter 5 number of lines, n=5
  33.   printf("\n Enter number of lines: ");
  34.   scanf("%d",&n);
  35.  
  36.   printf("\n");
  37.  
  38.   for(i=0; i<=n; i++)
  39.   {
  40.     ch = 'A';
  41.  
  42.     for(j=0; j<=n-i; j++, ch++)
  43.       printf("%c",ch);
  44.  
  45.     if(i==0)
  46.       printf("%c",ch);
  47.     else
  48.       for(k=0; k<(2*i)+1; k++)
  49.         printf(" ");
  50.  
  51.     ch--;
  52.     for(j=0; j<=n-i; j++, ch--)
  53.       printf("%c",ch);
  54.  
  55.     printf("\n");
  56.   }
  57.  
  58.   return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement