Q. Write a c program to print the following star structure:
*********
*******
*****
***
*
***
*****
*******
*********
Ans.
/*c program for print the star structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,n,r,c,sp;
printf("Enter number of rows: ");
scanf("%d", &num);
printf("\n");
n=num;
for(r=1; r<=num; r++)
{
for(sp=1; sp<=r; sp++)
printf(" ");
for(c=1; c<=n; c++)
printf("*");
for(c=num-r; c>=1; c--)
printf("*");
n--;
printf("\n");
}
for(r=2; r<=num; r++)
{
for(sp=num-r+1; sp>=1; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf("*");
for(c=r-1; c>=1; c--)
printf("*");
printf("\n");
}
return 0;
}
The output of above program would be:
*********
*******
*****
***
*
***
*****
*******
*********
Ans.
/*c program for print the star structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,n,r,c,sp;
printf("Enter number of rows: ");
scanf("%d", &num);
printf("\n");
n=num;
for(r=1; r<=num; r++)
{
for(sp=1; sp<=r; sp++)
printf(" ");
for(c=1; c<=n; c++)
printf("*");
for(c=num-r; c>=1; c--)
printf("*");
n--;
printf("\n");
}
for(r=2; r<=num; r++)
{
for(sp=num-r+1; sp>=1; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf("*");
for(c=r-1; c>=1; c--)
printf("*");
printf("\n");
}
return 0;
}
The output of above program would be:
Screen shot for specific star structure C program |
No comments:
Post a Comment