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?