Pattern Till N and Reverse - C - Spicy Coders

Recent

Saturday, September 02, 2017

Pattern Till N and Reverse - C

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. 

Output Format: 2N lines as shown in the Example Input/Output. 

Boundary Conditions: 2 <= N <= 100 

Example Input/Output 1: 
Output: 
22 
333 
4444 
4444 
333 
22 
1 

Example Input/Output 2: 
Output: 
22 
333 
4444 
55555 
666666 
7777777 
7777777 
666666 
55555 
4444 
333 
22 
1

Source Code:

#include<stdio.h>
#include <stdlib.h>

int main()
{
int n,a=1,i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
{
    for(j=0;j<=i;j++)
        printf("%d",a);
    a++;
    printf("\n");
}
for(i=0;i<n;i++)
{
    a--;
    for(j=0;j<n-i;j++)
        printf("%d",a);
    printf("\n");
}

}

No comments:

Post a Comment