programming-examples/c/Pattern_Programs/P_1_121_1..c

60 lines
1.1 KiB
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
/* Pattern Problem
1
121
12321
1234321
12321
121
1
*/
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j ;
clrscr() ;
printf("Required pattern is as follows: \n") ;
for(i=1 ; i<=4 ; i++)
{
/* Managing spaces */
for(j=1 ; j<=4-i ; j++)
printf(" ") ;
/* Printing from left to Centre */
for(j=1 ; j<=i ; j++)
printf("%d", j) ;
/* Printing to the right of Centre */
for(j=i-1 ; j>=1 ; j--)
printf("%d", j) ;
printf("\n") ;
}
for(i=4-1 ; i>=1 ; i--)
{
/* Managing spaces */
for(j=4-i ; j>=1 ; j--)
printf(" ") ;
/* Printing from left to Centre */
for(j=1 ; j<=i ; j++)
printf("%d", j) ;
/* Printing to the right of Centre */
for(j=i-1 ; j>=1 ; j--)
printf("%d", j) ;
printf("\n") ;
}
getch();
}
/*
Output:
Required pattern is as follows:
1
121
12321
1234321
12321
121
1
*/