Posted by: Sourav | May 14, 2015

Another nice pattern in C


#include<stdio.h>
//#include<conio.h>
int main()
{
int r,c,num=1,len,i;
printf(“Enter Length”);
scanf(“%d”,&len);
for(r=1;r<=len;r++)
{
printf(“\n”);
for(c=(10-(num+r));c>0;c–)
printf(” “);
for(c=1;c<=r;c++)
{
printf(“%d “,num);
num++;
}
num–;
i=r-1;
for(c=1;c<=i;c++)
{
num–;
printf(“%d “,num);
}
num++;
}
printf(“\n”);
//getch();
return 0;
}

 

This will produce a pattern like this

 

1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: