#include
#define Mx 20
#define My 20
void draw(int base,int height);
int main()
{
// draw(5,4);
// draw(5,4);
// draw(15,6);
int a=2,h=0;
char c;
while(a%2==0){
printf("Enter the base:");
scanf("%d",&a);
if (a%2==0)
printf("only odd length is allowed\n");
getchar();
}
while (h==a || h<2){
printf("Enter the height :");
scanf("%d",&h);
if (h==a)
printf("\nthe height you entered makes an Equilateral triangle.\n");
if (h<2)
printf("\nheight must be greater than 1.\n");
getchar();
}
draw(a,h);
getchar();
}
void draw(int base,int height){
if(base%2==0) {
printf("The length of the base its not an odd number \n");
return ;
}
int i=0,j;
int a=i;
int b=base,t;
// (base>height)?t=base:t=height;
int howmanystars=(base)/(height-1);
float stars=height-1;
stars=(float)(base)/stars-0.5;
if (howmanystars<=stars)
howmanystars++;
int h=1;
for (i=0;i<=height;i++){
if (i==height-1)
h=base;
for (int k=0;k<=(base-h+1)/2;k++)
printf(" ");
for (j=0;j<=h;j++)
printf("*");
h=h+howmanystars;
printf("\n");
}
}
Creating Isosceles Triangle in C
Creating Isosceles Triangle
No comments:
Post a Comment