Star (*) Praymid
Q. Write a C program to print the following triangle:
* | ||||||||||
* | * | * | ||||||||
* | * | * | * | * | ||||||
* | * | * | * | * | * | * | ||||
* | * | * | * | * | * | * | * | * | ||
* | * | * | * | * | * | * | * | * | * | * |
Ans.
/*c program for star pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num=6,r,c,sp;
for(r=1; num>=r; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
for(c=r; c>=1; c--)
printf("*");
for(c=r; c>1; c--)
printf("*");
printf("\n");
}
getch();
#include<stdio.h>
#include<conio.h>
int main()
{
int num=6,r,c,sp;
for(r=1; num>=r; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
for(c=r; c>=1; c--)
printf("*");
for(c=r; c>1; c--)
printf("*");
printf("\n");
}
* | ||||||||||
* | * | * | ||||||||
* | * | * | * | * | ||||||
* | * | * | * | * | * | * | ||||
* | * | * | * | * | * | * | * | * | ||
* | * | * | * | * | * | * | * | * | * | * |
No comments:
Post a Comment