Need help with short program!!!
Hi,
I need help building a program that is supposed to come out looking like this using nested for loops. Cans someone please help!
1
12
123
1234
4321
_ 321
__ 21
___ 1
Those are spaces in the bottom 3
I currently have this coming out:
1
12
123
1234
1234
4321
4321
32
21
1
with this coding:
#include <iostream>
using namespace std;
int main(){
for (int i=1; i<5; i++)
{
cout<<i;
cout<<"\n";
for (int j=1; j<i+1; j++)
{
cout<<j;
}
}
cout<<"\n";
for (int n=4; n>=1; --n)
{
cout<<n;
cout<<"\n";
for (int m = 4; m>=n; m--)
{
cout<<m;
}
}
return 0;
}
Re: Need help with short program!!!
Welcome to Codeguru.
Next time when you are posting pieces of code, use these
Convert 'm' to a string (you can use sprintf (%d)). Before outputting the 'm'-string write the missing '_' chars according to the length of the 'm'-string.
Re: Need help with short program!!!
Well, you missed to output first some spaces (m-n).