Search This Blog

Monday, 7 May 2018

Identity Matrix in C++ by using nested loop


#include <iostream>  //for input and output

using namespace std;

//Main function begins
main()
{
//Declare the variables
int row, col, num=3;

cout << "Enter the Number order of the Matrix";
cin >> num;
//for loop structure
for (row=1;row<=num;row++)
{
for (col=1;col<=num;col++)
{
if (row==col)
cout << 1;
else
cout << 0;
}
cout <<endl;
}

}

No comments:

Post a Comment