Write an algorithm, draw a flowchart and write a program code to display 3*3 Identity Matrix.
using namespace std;
// Write an algorithm, draw a flowchart and write a program code to display 3*3 Identity Matrix.
#define N 3
int main()
{
int I[N][N],r,c;
cout<<"\n\t"<<N<<" x "<<N<<" Identity Matrix:\n";
for(r=0;r<N;r++)
{
for(c=0;c<N;c++)
{
I[r][c] = 0;
if(r==c) I[r][c] = 1;
cout<<"\t"<<I[r][c];
}
cout<<"\n";
}
return(0);
}
// Write an algorithm, draw a flowchart and write a program code to display 3*3 Identity Matrix.
Algorithm:
- Define the Matrix Size as N
- Initialize an Identity matrix I[N][N] with NxN matrix size
- Initialize a double for loop from r=0 to N and c=0 to N
- if r==c, I[r][c] = 1
else I[r][c] = 0;
- End the for loop
- display the Identity matrix
- end
Comments
Leave a comment