Pattern Printing - Till N & Reverse
The program must accept an integer N and print 2N lines as shown in the Example Input/Output.
Input Format:
The first line contains N.
The first line contains N.
Output Format:
2N lines as shown in the Example Input/Output.
2N lines as shown in the Example Input/Output.
Boundary Conditions:
2 <= N <= 100
2 <= N <= 100
Example Input/Output 1:
4
4
Output:
1
22
333
4444
4444
333
22
1
1
22
333
4444
4444
333
22
1
Example Input/Output 2:
7
7
Output:
1
22
333
4444
55555
666666
7777777
7777777
666666
55555
4444
333
22
1
Code:
1
22
333
4444
55555
666666
7777777
7777777
666666
55555
4444
333
22
1
Code:
#include<stdio.h>
#include <stdlib.h>
void main()
{
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=0;j<i;j++)
printf("%d",i);
printf("\n");
}
for(i=n;i>=1;i--)
{
for(j=0;j<i;j++)
printf("%d",i);
printf("\n");
}
}
No comments:
Post a Comment