Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- C program to print following character pyramid:
- Enter number of lines: 5
- ABCDEFGFEDCBA
- ABCDE EDCBA
- ABCD DCBA
- ABC CBA
- AB BA
- A A
- Enter number of lines: 7
- ABCDEFGHIHGFEDCBA
- ABCDEFG GFEDCBA
- ABCDEF FEDCBA
- ABCDE EDCBA
- ABCD DCBA
- ABC CBA
- AB BA
- A A
- */
- #include<stdio.h>
- int main()
- {
- int i,j,k,n;
- char ch;
- // enter 5 number of lines, n=5
- printf("\n Enter number of lines: ");
- scanf("%d",&n);
- printf("\n");
- for(i=0; i<=n; i++)
- {
- ch = 'A';
- for(j=0; j<=n-i; j++, ch++)
- printf("%c",ch);
- if(i==0)
- printf("%c",ch);
- else
- for(k=0; k<(2*i)+1; k++)
- printf(" ");
- ch--;
- for(j=0; j<=n-i; j++, ch--)
- printf("%c",ch);
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement