Star Pattern - 3
********** **** **** *** *** ** ** * * * * ** ** *** *** **** **** **********
#include<stdio.h>
int
main()
{
int noofrows,space,row,star;
scanf("%d",&noofrows);
int
i;
// Loop to print upper half of the pattern
for(i=1;i<=(noofrows*2)+1;i++)
printf("*");printf("\n");
for(row=1;row<=noofrows;row++)
{
for(space=noofrows-row;space>=0;space--)
printf("*");
for(star=1;star<=(row*2)-1;star++)
printf(" ");
for(space=noofrows-row;space>=0;space--)
printf("*");
printf("\n");
}
// Loop to print lower half of the pattern
for(row=noofrows-1;row>=1;row--)
{
for(space=noofrows-row;space>=0;space--)
printf("*");
for(star=1;star<=(row*2)-1;star++)
printf(" ");
for(space=noofrows-row;space>=0;space--)
printf("*");
printf("\n");
}
for(i=1;i<=noofrows*2+1;i++)
printf("*");
return 0;
}
(or)
#include <stdio.h>int main()
{
int i, j, n;
printf("Enter value of n : ");
scanf("%d", &n);
// Loop to print upper half of the pattern
for(i=1; i<=n; i++)
{
for(j=i; j<=n; j++)
{
printf("*");
}
for(j=1; j<=(2*i-2); j++)
{
printf(" ");
}
for(j=i; j<=n; j++)
{
printf("*");
}
printf("\n");
}
// Loop to print lower half of the pattern
for(i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
printf("*");
}
for(j=(2*i-2); j<(2*n-2); j++)
{
printf(" ");
}
for(j=1; j<=i; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment