TASK-
Write a C program to Generate following pattern:
\n is used to shift to new line : see the code:
Crack for pattern:
- 1st and last line has full stars it mean a condition is required for 1st and last line.
- Other than 1st and last line each line has two stars and some space between them.
CODE:
#include<stdio.h> //star pattern
int main(){
int i,j,n=5; //Here n is taken 5 you may increase or take from user: n is number of rows
for (i=0;i<5;i++) //5 rows so 5 Iteration
{
if (i==0 || i==4) // Because at start and end we find a full line of *
{
for (j=0;j<9;j++) //Here the stars of up and down line are 9 you may change
printf("*");
}
else
{
printf("*");
for (j=1;j<8;j++)
printf(" "); // Creating space between two stars
printf("*");
}
printf("\n");
}
getchar();
return 0;
}
Expected Output:
Nice information thanx for sharing
ReplyDelete