Pages

Sunday, 14 June 2015

Star pattern 14

Star Pattern - 14 - Program in C

Coding:

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

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