Home » Ask & Discuss » Other Courses » Computer Applications « Back to Discussion



Computer Applications

yuvashree's Avatar
Cool goIITian

Joined: 13 Jul 2008
Post: 54
4 Oct 2008 12:18:22 IST
0 People liked this
5
734 View Post
WAP to determine whether a matrix is identity one or not?
None

WAP to determine whether a matrix is identity one or not?


Share this article on:

Comments (5)

Sagar Saxena's Avatar

Forum Expert
Joined: 8 Oct 2008
Posts: 7221
17 Oct 2008 23:26:06 IST
4 people liked this

#include<stdio.h>

#include<conio.h>



void main()

{

int mat[5][5],order,i,j,flag=0;



clrscr();

printf("\n Enter a square matrix to check identity");

printf("\n\n Enter its order(n*n) ");

scanf("%d",&order);



for(i=0;i<order;i++)

{

printf("\n");

for(j=0;j<order;j++)

{

printf(" %d,%d: ",i+1,j+1);

scanf("%d",&mat[i][j]);

}

}



for(i=0;i<order;i++)

{

for(j=0;j<order;j++)

{

if(i==j)

{

if(mat[i][j]!=1)

{

flag=1;

break;

}

}

else

{

if(mat[i][j]!=0)

{

flag=1;

break;

}

}

}

}



printf("\n The given matrix is ");

if(flag==0)

printf("an identity matrix.");

else

printf("not an identity matrix.");



getch();

}

Shankhadip Majumder's Avatar

Cool goIITian

Joined: 25 Apr 2008
Posts: 55
28 Oct 2008 13:27:38 IST
0 people liked this

if sum of all elements is no of rows or no columns and product of all left diagonal elements is equal to 1 then the matrix is an identity matrix,rate if you like the idea... 

Shankhadip Majumder's Avatar

Cool goIITian

Joined: 25 Apr 2008
Posts: 55
28 Oct 2008 20:31:31 IST
0 people liked this

plz rate me


 

Shankhadip Majumder's Avatar

Cool goIITian

Joined: 25 Apr 2008
Posts: 55
29 Oct 2008 20:12:52 IST
1 people liked this

 


java (but understandable)


sum=0 s=0,p=1;


for(i=0;i<n;i++)


{

for(j=0;j<n;j++)


{if(i==j){

p=p*a[i][j];


s=s+a[i][j];}


sum=sum+a[i][j];


}


if(s==sum&&p==1)


System.out.println("IDENTITY MATRIX");


else


plz rate me

Shankhadip Majumder's Avatar

Cool goIITian

Joined: 25 Apr 2008
Posts: 55
31 Oct 2008 17:38:33 IST
0 people liked this

you could change.. the pgm & check whether sum of left diagonal elements is equal to n(no of rows or columns)consider


1


       -1


                1


                      -1


all other elements are zero but my pgm would proclaim it to be a identity matrix sorry for my blip,\...




Quick Reply


Reply

Some HTML allowed.
Keep your comments above the belt or risk having them deleted.
Signup for a avatar to have your pictures show up by your comment
If Members see a thread that violates the Posting Rules, bring it to the attention of the Moderator Team
Free Sign Up!

Preparing for IIT-JEE ?

Arihant Revision Package for IIT JEE - Books, Practice Tests + Rank Predictor


@ INR 1,995/-

For Quick Info

Name

Mobile No.

Find Posts by Topics

Physics.

Topics

Mathematics.

Chemistry.

Biology

Parents

Board

Fun Zone

Sponsored Ads