Pages

Sunday, 14 June 2015

Star pattern 13

Star Pattern - 13 - program in C

Coding:

#include
int main()
{
int i,j,n,m,s=1;
printf("Please enter the number of lines:");
scanf("%d",&n);
if(n%2==0)
n=n+1;
for(i=1;i<=n;i++)
printf("*");
m=n/2;
for(i=1;i<m;i++)
{
printf("\n");
for(j=i;j<=m;j++)
printf("*");
for(j=1;j<=s;j++)
printf(" ");
for(j=i;j<=m;j++)
printf("*");
s=s+2;
}
for(i=1;i<=m;i++)
{
printf("\n");
for(j=1;j<=i;j++)
printf("*");
for(j=1;j<=s;j++)
printf(" ");
for(j=1;j<=i;j++)
printf("*");
s=s-2;
}
printf("\n");
for(i=1;i<=n;i++)
printf("*");
return 0;
}

Output:
Please enter the number of lines:5
*****
** **
*   *
** **
*****