Answer to Question #305388 in C++ for Swapy

Question #305388

Write an algorithm, draw a flowchart and write a program code to display 3*3 Identity Matrix.

1
Expert's answer
2022-03-03T09:59:51-0500
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









Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog