Q. Write a C program to print a V-Shape Pyramid as:
* *
* *
*
Ans.
/*how to print v-shape pyramid in c*/
#include<stdio.h>
int main()
{
int num=3,n,r,c,sp,s;
n=num;
for(r=1; r<=num; r++,n=n-2)
{
for(sp=r; sp>1; sp--)
printf(" ");
printf("*");
for(s=n; s>=1; s--)
printf(" ");
if(r<num)
printf("*");
printf("\n");
}
getch();
return 0;
}
You might also like:
* *
* *
*
Ans.
/*how to print v-shape pyramid in c*/
#include<stdio.h>
int main()
{
int num=3,n,r,c,sp,s;
n=num;
for(r=1; r<=num; r++,n=n-2)
{
for(sp=r; sp>1; sp--)
printf(" ");
printf("*");
for(s=n; s>=1; s--)
printf(" ");
if(r<num)
printf("*");
printf("\n");
}
getch();
return 0;
}
/************************************************************
The output of above program would be:
*************************************************************/
Figure: Screenshot for How To Print V-Shape Pyramid In C |
You might also like:
- How To Print E-Shape Pyramid In C
- How To Print M-shape Pyramid In C
- How To Print X-Shape Pyramid In C
- Big List of 98+ C Pyramid Programs
- Latest 100+ Pyramid Programs list
No comments:
Post a Comment