-
March 12th, 2009, 01:52 PM
#1
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;
}
-
March 12th, 2009, 02:47 PM
#2
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.
-
March 12th, 2009, 03:33 PM
#3
Re: Need help with short program!!!
Well, you missed to output first some spaces (m-n).
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|