Tuesday 3 September 2013

C Programming for beginners, Patterns using nested for loop, Pattern 11

Pattern 11

write a prog. to print following pattern, for n=5

*
***
*****
*******
*********
*******
*****
***
*



#include<conio.h>
#include<stdio.h>
void main()
{
int n=0,i,j;
clrscr();
printf("Enter N:");
scanf("%d",&n);
printf("\n\n");
for(i=1;i<=n;i++)
{

for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
for(j=2;j<=i;j++)
{
printf("*");
}
printf("\n");
}
n=n-1;
for(i=n;i>=1;i--)
{
for(j=i;j<=n;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
for(j=2;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}


O/P:

No comments:

Post a Comment

Contact Form

Name

Email *

Message *