programming-examples/c/Pattern_Programs/P_1_121..c
2019-11-15 12:59:38 +01:00

52 lines
888 B
C

/* Pattern Problem
1
121
12321
1234321
...
*/
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, n ;
clrscr() ;
printf("Enter the number of lines: ") ;
scanf("%d", &n) ;
printf("Required pattern is as follows: \n") ;
for(i=1 ; i<=n ; i++)
{
/* Managing spaces */
for(j=1 ; j<=n-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") ;
}
getch();
}
/*
Give one extra space in each printf() if the pattern is:
1
1 2 1
1 2 3 2 1
*/
/*
Output:
Enter the number of lines: 4
Required pattern is as follows:
1
121
12321
1234321
*/