write program with two nested loops that produces the following.

Sep 29, 2012 at 9:02pm
ABCD
ABC
AB
A
Sep 29, 2012 at 9:06pm
Why would you need two nested loops for this?
Sep 29, 2012 at 9:12pm
one for printing it 4 times, one to print x amount of characters.

Okay, did it, now what?
Sep 29, 2012 at 9:15pm
Just one loop should do...I just made and tested this code, so it works.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main() {
	string letters = "ABCD";
	for (int i = 4; i > 0; i--) {
		// output substring of 'letters' from 0 to 'i'
	}
	
	return 0;
}
Last edited on Sep 29, 2012 at 10:03pm
Sep 29, 2012 at 9:17pm
technically yes, but if you didn't take away letters you would have to use two loops, or if the string was a constant

and can you edit your post? this is obviously a homework question, answering homework isn't 'allowed'
Last edited on Sep 29, 2012 at 9:18pm
Sep 30, 2012 at 1:13am
1
2
3
4
5
6
7
8
9
#include <iostream>

int main()
{
    for ( int i=0; i<1 ; ++i )
        for ( int j=0; j<1 ; ++j )
            for ( int k=0; k<1 ++k )
                std::cout << "ABCD\nABC\nAB\nA\n" ;
}


Edit: fixed!
Last edited on Sep 30, 2012 at 1:30am
Sep 30, 2012 at 1:19am
^^ Thats only one nested loop :)
Sep 30, 2012 at 1:27am
Damn you, sir.
Topic archived. No new replies allowed.