C program to print the equilateral triangle of stars
sample input and output:
Program:
#include<stdio.h>
int main()
{
int height_pyramid;
do
{
printf("how much height do tou want to print: ");
scanf("%d",&height_pyramid);
}while (height_pyramid < 1 || height_pyramid > 23);
int i,j,k,n;
n=height_pyramid;
for (i=1, j=n; i<=j; i++,n--)
{
for(k=0;k<n-1;k++)
printf(" ");
for(k=0;k<i;k++)
printf("* ");
printf("\n");
}
return 0;
}
int main()
{
int height_pyramid;
do
{
printf("how much height do tou want to print: ");
scanf("%d",&height_pyramid);
}while (height_pyramid < 1 || height_pyramid > 23);
int i,j,k,n;
n=height_pyramid;
for (i=1, j=n; i<=j; i++,n--)
{
for(k=0;k<n-1;k++)
printf(" ");
for(k=0;k<i;k++)
printf("* ");
printf("\n");
}
return 0;
}
No comments:
Post a Comment