Q. Write a C program to print the following V symbol star pyramid as:
* *
* *
* *
*
Ans.
/*c pyramid program for v-symbol*/
#include<stdio.h>
int main()
{
int num=4,r,c,sp;
for(r=1,c=num+1; r<=num; r++,c=c-2)
{
for(sp=r; sp>1; sp--)
printf(" ");
printf("*");
for(sp=c; sp>=1; sp--)
printf(" ");
if(c>=1)
printf("*");
printf("\n");
}
getch();
return 0;
}
The output of above program would be:
* *
* *
* *
*
Ans.
/*c pyramid program for v-symbol*/
#include<stdio.h>
int main()
{
int num=4,r,c,sp;
for(r=1,c=num+1; r<=num; r++,c=c-2)
{
for(sp=r; sp>1; sp--)
printf(" ");
printf("*");
for(sp=c; sp>=1; sp--)
printf(" ");
if(c>=1)
printf("*");
printf("\n");
}
getch();
return 0;
}
The output of above program would be:
Figure : Screen shot for V-Shape pyramid C program |
No comments:
Post a Comment