Write a program to print the below pattern for the given N
Input Format
The input contains the integer value N
Output Format
Print the required pattern
Constraint
1<=N<=10^9Sample Input 1
1234
Sample Output 1
1 2 3 4 2 3 4 3 4 4 3 4 2 3 4 1 2 3 4
Sample Input 2
34345
Sample Output 2
3 4 3 4 5 4 3 4 5 3 4 5 4 5 5 4 5 3 4 5 4 3 4 5 3 4 3 4 5
Sample Input 3
1009001
Sample Output 3
1 0 0 9 0 0 1 0 0 9 0 0 1 0 9 0 0 1 9 0 0 1 0 0 1 0 1 1 0 1 0 0 1 9 0 0 1 0 9 0 0 1 0 0 9 0 0 1 1 0 0 9 0 0 1
Code:
#include<stdio.h>
int main()
{
long long n;
scanf("%lld",&n);
int i=0,a[100];
while(n)
{
int temp = n%10;
a[i++] = temp;
n=n/10;
}
int k =0;
int b[100];
int inc1 =i-1;
for(int j =0;j<i;j++)
{
b[j]=a[inc1];
inc1--;
}
for(int j=0;j<i;j++)
{
a[j] = b[j];
}
for(int j=0; j<i;j++)
{
for( k =0;k<j;k++) printf(" ");
for(int l=k;l<i;l++) printf("%d ",a[l]);
printf("\n");
}
int l;
int inc =0;
for(int j=0;j<i-1;j++)
{
inc = 0;
for( l =j;l<k-1;l++)
{ printf(" ");
inc++;
}
for(int d =inc;d<i;d++) printf("%d ",a[d]);
printf("\n");
}
}
Code language: C/AL (cal)