#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,n;
clrscr();
printf("\nEnter the number of rows :- ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf(" *");
}
for(k=1;k<=2*(n-i)-1;k++)
{
printf(" ");
}
if(i==n)
{
for(j=1;j<i;j++)
{
printf(" *");
}
}
else
{
for(j=1;j<=i;j++)
{
printf(" *");
}
}
printf("\n");
}
n=n-1;
for(i=0;i<n;i++)
{
for(j=n;j>i;j--)
{
printf(" *");
}
for(k=1;k<=2*i+1;k++)
{
printf(" ");
}
for(j=n;j>i;j--)
{
printf(" *");
}
printf("\n");
}
getch();
}
Output:-
Enter the number of rows :- 5
Back to 'C Language Programs'
No comments:
Post a Comment