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