Hello I'm new here, I try this site when I found the url in the web when I am trying to solve my problem. And I became interested and join.

Hope you can help me with this one:

I have this program:

#include <stdio.h>


main()


{


char input;
int base,a,b,c,d,e;



printf("Input:");
scanf("%c", &input);
printf("Base:");
scanf("%i", &base);



e=base;


for (a=0;a<=base-1;a++)


{


for (d=0;d<=e-a;d++)


printf (" ");
for (b=0;b<=a;b++)


{


printf("%c", input);



}


printf("\n");
}


}

when I run this the result will be a triangle made of a inputed letter.

Input:A
Base:5
A
AA
AAA
AAAA
AAAAA
AAAAAA
Press any key to continue

the problem is I want the input to look like a equilateral triangle but the result is a right triangle.

There's something wrong with the second for statement but until now I don't know how to fix it.

I try changing the condition d<=e-a at the second for statement to d<=50-a but still it doesn't work.

what shall I do...

by the way I'm new with c programming.

(about the posting I am still studying how it works, so for the meantime I just copy and paste my codes... sorry for that :p)

>(about the posting I am still studying how it works, so for the meantime I just copy and paste my codes... sorry for that :p)

What's so hard to understand?

#include <stdio.h>

main()

{

char input;
int base,a,b,c,d,e;


printf("Input:");
scanf("%c", &input);
printf("Base:");
scanf("%i", &base);


e=base;

for (a=0;a<=base-1;a++)

{

for (d=0;d<=e-a;d++)

printf (" ");
for (b=0;b<=a;b++)

{

printf("%c", input);


}

printf("\n");
}

}

Yes Ive done it hehe code, sorry for the inconvenience.

sorry for that. I had just gotten the trick for posting. sorry for the inconvenience..

sorry for that. I had just gotten the trick for posting. sorry for the inconvenience..

Futher homework for you: Formatting C code
A possible solution:

#include <stdio.h>

int main ( void ) 
{

    char input;
    int base,a,b;


    printf("Input:");
    scanf("%c", &input);
    printf("Base:");
    scanf("%i", &base);

    for ( a = 1; a <= base; a++)
    {
        for ( b = 0; b < base-a; b++ )
            putchar(' ');
        for ( b = 0; b < 2*a - 1; b++ ) 
            putchar( input );
        putchar( '\n' );
    }
    return 0;
}

Thank you and also the reading assignment helps enlightening me. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.