1 1 1 1

In our Computer Education subject, we are asked to write a program that will input an integer and will produce "*" half-triangle and whole triangle form; number half-triangle and whole triangle form, like this:

(half-triangle)
input: 5

*
**
***
****
*****
(whole triangle)
input: 5
*
* *
* * *
* * * *
* * * * *


(half-triangle)
input: 5

1
22
333
4444
55555

(whole triangle)
input: 5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5


Our teacher gave the source code of the half-triangle asterisk:
#include <iostream.h>
#include <conio.h>

void main(void)
{
int n,d;
char answer;
do{
cout<<"\nInput an integer-->";
cin>>n;
for (int a=1; a<=(n);a++)
{
d=a;
for (int c=0; c<=d;c++)
{
cout<<"1";
}
cout<<"\n";
}
cout<<"\n";
cout<<"\nInput again? [y/n]-->";
cin>>answer;
}while (answer=='y'||answer=='Y');

}

so the half-triangle asterisk is a bonus...we only need to modify it for the other three...
my problem now is the source code of the three...I'm still working on the number half-triangle...so how should I do it??? I couldn't get it right...
how do I make the values appear like
1
22
333... using the for-statement?
how will i align them all at the center?
Last edited on
[code] "Use code tags" [/code]
You are using deprecated headers, conio.h is not used (and it shouldn't), and main must return int.
Also the output is incorrect.

If the input is not greater than 9, to centre the triangle you need to count the character in the base to know how many spaces do you need to output.
cout<<"1"; Change that to a variable that count the row.
search the beginners forum for a diamond shape ex, you can easily modify it for half triangle.
Topic archived. No new replies allowed.