Write a program to print below pattern.
Input:
An integer
Output:
As displayed in sample output
Note: Get input using command line.
Example
Input&Output:
Input:
5
Output
1
1
12
21
123
321
1234 4321
1234554321
Input: 7
Output
1 1
12
21
123
321
1234
4321
12345
54321
123456
654321
12345677654321
Solution-
1:
#include<stdio.h>
int main(int argc, char *argv[])
{
int i,j,k;
int n=atoi(argv[1]);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(j<=i)
printf("%d",j);
else
printf(" ");
}
for(j=n;j>=1;j--)
{
if(j<=i)
printf("%d",j);
else
printf(" ");
}
printf("\n");
}
return 0;
}
Solution-
2:
#include<iostream>
#include<stdlib.h>
using namespace std;
int main(int argc, char *argv[])
{
int n=atoi(argv[1]);
int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=2*n;j++)
{
if(j<=n&&j<=i)
cout<<j;
else if(j>=2*n-i+1)
cout<<2*n-j+1;
else
cout<<" ";
}
cout<<endl;
}
}