Help with for loop pattern

Feb 26, 2014 at 11:30pm
hi can anyone help me convert this for loop to show this pattern but instead going the other way?


mmmmmm
mmmmm
mmmm
mmm
mm
m

[code]
for (i = 1; i <= num; i++)
{
for (j = num; j >= i; j--)
{
cout << ch; // displays pattern
}
cout << endl;
Last edited on Feb 26, 2014 at 11:41pm
Feb 27, 2014 at 12:45am
I'm not sure exactly what you mean by going the other way. If you need blank spaces to print out before the character in the pattern, you can set up an if... else statement in the inner for loop (that controls the column being printed).
Feb 28, 2014 at 6:59pm
I'm not sure whether this is what you mean, but this program outputs the following:


mmmmmmm
mmmmmm
mmmmm
mmmm
mmm
mm
m


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>

using namespace std;

int main(){
	
	string what = "m";
	int start = 7;
	int y;

	for (int x = start; x > 0; --x){
		y = 0; 
		while (y != x){
			cout << what;
			++y;
		}
		cout << endl;
	}
	return 0;
}
Topic archived. No new replies allowed.