C++ or C program to find Reciprocal of a given matrix.

file name:- recmat.cpp

#include<iostream.h>
#include<conio.h>
#define R 2
#define C 2
void main(){
int A[R][C],B[R][C],i,j;
clrscr();
cout<<"Enter elements of matrix A"<<endl;
for(i=0;i<R;i++){
for(j=0;j<C;j++){
cout<<"Enter A["<<i<<"]["<<j<<"]= ";
cin>>A[i][j];
}}
cout<<"Matrix A="<<endl;
for(i=0;i<R;i++){
for(j=0;j<C;j++){
cout<<A[i][j]<<" ";
}
cout<<endl;
}
for(i=0;i<R;i++){
for(j=0;j<C;j++){
B[i][j]=A[j][i];
}}
cout<<"Reciprocal of A="<<endl;
for(i=0;i<R;i++){
for(j=0;j<C;j++){
cout<<B[i][j]<<" ";
}
cout<<endl;
}
getch();
}

file name:- recmat.c

#include<stdio.h>
#include<conio.h>
#define R 2
#define C 2
void main(){
int A[R][C],B[R][C],i,j;
clrscr();
printf("Enter elements of matrix A\n");
for(i=0;i<R;i++){
for(j=0;j<C;j++){
printf("Enter A[%d][%d]=",i,j);
scanf("%d",&A[i][j]);
}}
printf("Matrix A=\n");
for(i=0;i<R;i++){
for(j=0;j<C;j++){
printf("%d ",A[i][j]);
}
printf("\n");
}
for(i=0;i<R;i++){
for(j=0;j<C;j++){
B[i][j]=A[j][i];
}}
printf("Reciprocal of A=\n");
for(i=0;i<R;i++){
for(j=0;j<C;j++){
printf("%d ",B[i][j]);
}
printf("\n");
}
getch();
}

No comments:

Post a Comment

Stack Data Structure, Push, Pop and Peek Operations , Applications of Stack

Stack is a linear data structure. It is collection of ordered data elements. It is also known as LIFO system (last in first out). It means i...