0
aliz_khanz's Avatar, Join Date: Apr 2011
Go4Expert Member
Sir , its less and less related with the complexities of mathematics. I understand your concern but please remember that we are drawing particular letters(in this case asterik *) and with the help of that , we are making an isoceles triangle. the limit is not given in the question for base and height.hope you get me !
0
virxen's Avatar, Join Date: Nov 2009
Pro contributor
if i enter base=3 and height=9 what you draw?

i know its just an exercise but there must be some restrictions

for example base length must be greater than the height.
are you sure that there are not any more restrictions in your exercise that you forgot to mention?
0
aliz_khanz's Avatar, Join Date: Apr 2011
Go4Expert Member
Sir I am 110% positive that there are no other restrictions in my question.
0
virxen's Avatar, Join Date: Nov 2009
Pro contributor
you can try this

Code:
#include<stdio.h>
#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);
int h=1;
for (i=0;i<height;i++){
    for (int k=0;k<(base-h+1)/2;k++)
        printf(" ");
    for (j=0;j<h;j++)
        printf("*");
    h=h+howmanystars;
    printf("\n");
}
                   
}

Last edited by virxen; 10Apr2011 at 23:56..
0
aliz_khanz's Avatar, Join Date: Apr 2011
Go4Expert Member
Ma Man , Do I Love you or what ???? Thanks Heaps !!!!!!!
0
aliz_khanz's Avatar, Join Date: Apr 2011
Go4Expert Member
just one problem. when i type the legth of base greater than the height , it draws a straight line .......... can you please fix it ?
0
virxen's Avatar, Join Date: Nov 2009
Pro contributor
Quote:
Originally Posted by aliz_khanz View Post
just one problem. when i type the legth of base greater than the height , it draws a straight line .......... can you please fix it ?
what base and height did you give?
0
aliz_khanz's Avatar, Join Date: Apr 2011
Go4Expert Member
I placed 11 as base and 7 as height then again 15 as base and 9 as height !
0
virxen's Avatar, Join Date: Nov 2009
Pro contributor
as i told you before ,what you want isn't easy to accomplish.
it works only in some cases not for all.
for example you said base=11 and height=7 can you post the right shape you
expect to get?

i made some changes.
Code:
#include<stdio.h>
#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");
}
                   
}
aliz_khanz like this
0
aliz_khanz's Avatar, Join Date: Apr 2011
Go4Expert Member
Symmetry is whats lacking in the above programme. Also , when i Place 7 as base and 11 as height it gave me this


HTML Code:

B 7 
H 11

                   *
                   *
                   *
                   *
                   *
                   *
                   *
                   *
                   *
                   *
             * * * * * * *





HTML Code:
Height 7 Base 11


                     *
                    * *  
                   * * *
                  * * * *
                 * * * * *
                * * * * * * 
               * ********* * 

Last edited by aliz_khanz; 12Apr2011 at 18:02..