C++ matrix

Hello everyone,

I am working on an assignment for my CS class and I am wondering how to make my output look a certain way.

This code:

#include <iostream>

using namespace std;

int main()
{
int i, j;

for (i=5; i>=1; i--)
{
for (j=1; j !=i; j++)
cout << "#";
cout << "5";
cout << endl;
}
}

Output:

####5
###5
##5
#5
5

I am really close but I need my code to output:

####5
###5#
##5##
#5###
5####

How would I get my code to output that using the loop I already have?

I hope that makes sense and thank you for the help!
Last edited on
You have for (j=1; j !=i; j++) cout << "#"; that prints some # before the 5.
You have cout << "5"; that prints the 5.
You have cout << endl; that prints the end of the line.

That is what you do for one line.

You say that you want to print some # after the 5, but before the end of the line?

After cout << "5";
Before cout << endl;

How many # in each line? What is the value of i on those lines? Can you caluclate from the value of i the number of # that that line needs?
Topic archived. No new replies allowed.