Pages

Friday, 12 June 2015

Star pattern 12

Star pattern -12 - program in C

Coding:

#include<stdio.h>
void main()
{
int i,j,n,s,s1,k=1;
printf("Please enter no of lines(>2 and odd):");
scanf("%d",&n);
if(n%2)
{
s=n/2;
for(i=1;i<=s;i++)
{
for(j=1;j<=s-i+1;j++)
printf(" ");
k=1 ;
for(j=1;j<=2*i-1;j++)
{
if(k==1 || k==2*i-1)
printf("*");
else
printf(" ");
k++;
}
printf("\n");
}// First portion
k=1;
for(i=1;i<=n;i++)
{
if(k==1 ||k==n )
printf("*");
else
printf(" ");
k++;
}
s1=s;
for(i=1;i<=s;i++)
{
printf("\n");
for(j=1;j<=i;j++)
printf(" ");
k=1;
for(j=1;j<=2*s1-1;j++)
{
if(k==1 || k==2*s1-1)
printf("*");
else
printf(" ");
k++;
}
s1--;
}
}
else
printf("Wrong Input");
}

Output:
Please enter no of lines(>2 and odd):5
  *
 * *
*   *
 * *
  *