Write a program in C++ of a inverse matrix
//Question 3 Matrix
#include<iostream.h> #include<conio.h> #include<stdio.h> #include <string.h> void largest(int **a,int n) { int pi=0,pj=0,l=a[0][0]; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(a[i][j]>l) { l=a[i][j]; pi=i; pj=j; } } } cout<<"Position of largest="<<pi+1<<" "<<pj+1<<endl; } void slargest(int **a,int n) { int l=a[0][0],sl=0,pi=0,pj=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(a[i][j]>l) l=a[i][j]; else { sl=a[i][j]; pi=i; pj=j; } } } for(i=0;i<n;i++) { for(int j=0;j<n;j++) { if(a[i][j]>sl && a[i][j]<l) { sl=a[i][j]; pi=i; pj=j; } } } cout<<"Second Largest position="<<pi+1<<" "<<pj+1<<endl; } void sort(int **a,int n) { int x,i,j,t; for(x=0;x<n;x++) { for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(a[x][i]>a[x][j]) { t=a[x][i]; a[x][i]=a[x][j]; a[x][j]=t; } } } } } void display(int **a,int n) { cout<<endl; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cout<<a[i][j]<<"\t"; } cout<<endl; } } void main() { clrscr(); cout<<"Enter size of the matrix:"; int n; cin>>n; int **a; *a=new int[n]; for(int i=0;i<n;i++) a[i]=new int[n]; cout<<"Enter elements of the matrix:\n"; for(i=0;i<n;i++) { for(int j=0;j<n;j++) { cin>>a[i][j]; } } display(a,n); largest(a,n); slargest(a,n); sort(a,n); display(a,n); getch(); } |