1 2 3 4 5 6 7 |
DCBA CBA BA A |
The below code helps to print the above format
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#include "stdafx.h" #include <stdio.h> #include <stdlib.h> int main () { int iNum, iIndex, Ind1, iSpace = 0; char ch, chTemp; printf ("Enter the number of lines do you want to print"); scanf("%d", &iNum); ch = 'A'+iNum-1; chTemp = ch; for ( Ind1 = iNum ; Ind1 >= 1 ; Ind1-- ) { for ( iIndex = 1 ; iIndex <= iSpace; iIndex++) printf(" "); iSpace++; for ( iIndex = 1 ; iIndex <= Ind1 ; iIndex++ ) { printf("%c",chTemp); chTemp--; } printf("\n"); ch--; chTemp = ch; } getchar (); return 0; } |
The output of the above program is
1 2 3 4 5 6 7 8 9 |
Enter the number of lines do you want to print4 DCBA CBA BA A |