Question: The following function prints a natural number sequence across the diagonal of an n by n square matrix. Debug the code to fix all the

The following function prints a natural number sequence across the diagonal of an n by n square matrix. Debug the code to fix all the compilation and run-time errors, so that the code generates the desired output. For instance, when the num value passed to the function is 5, the output would look like the following.

 

1****

*2***

**3**

***4*

****5

void naturalDiagonal(int num); for (int i=0; i < num - 1; i++) { for (int j=1; j <= number; j++) { if i == j-1 { cout << i; } else { cout << "*"; } cout << endl; } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!