write program with two nested loops that produces the following.

ABCD
ABC
AB
A
Why would you need two nested loops for this?
one for printing it 4 times, one to print x amount of characters.

Okay, did it, now what?
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
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
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
^^ Thats only one nested loop :)
Damn you, sir.
Topic archived. No new replies allowed.