Skip to content

Instantly share code, notes, and snippets.

@rohangiriraj
Created April 29, 2018 13:28
Show Gist options
  • Save rohangiriraj/16395a20e29eede20f39b39a939e9dee to your computer and use it in GitHub Desktop.
Save rohangiriraj/16395a20e29eede20f39b39a939e9dee to your computer and use it in GitHub Desktop.
Pattern
#include<stdio.h>
int main()
{
int n,a=1,b=2,i,j,m,k,l=1,c=0;
m=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=n;j>=i;j--)
printf("%d",j);
if(i==1)
{
for(j=i+1;j<=n;j++)
printf("%d",j);
}
else
{
for(k=1;k<m;k++)
printf(" ");
for(j=i;j<=n;j++)
printf("%d",j);
}
m=m+2;
printf("\n");
}
m=(2*n-1)-4;
for(i=n-1;i>=1;i--)
{
for(j=n;j>=i;j--)
printf("%d",j);
for(k=0;k<m;k++)
printf(" ");
if(i==1)
{
for(j=2;j<=n;j++)
printf("%d",j);
}
else
{
for(j=i;j<=n;j++)
printf("%d",j);
}
m=m-2;
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment