Transpose Of the Matrix- Finding Minimum And Maximum Numbers
A recursive C function to find out the minimum and maximum numbers among the elements of every row in a given two dimensional array.Also calculate the transpose of the matrix. Source Code: #include<stdio.h> #include<conio.h> //defining functions int min(int a[30][30],int c,int i); int max(int a[30][30],int c,int i); //main program void main() { //declaring variables int a[30][30],b[30][30],m,n,i,j,r,c,t; int M,N; clrscr(); printf("This is a program to find the max,min,transpose of the matrix\n"); //taking input from the user printf("\n Enter the number of the row in the matrix:"); scanf("%d",&r); printf("\n Enter the number of the column in the matrix:"); scanf("%d",&c); printf("\nEnter the elements of matrix\n\n"); //iteration of loop for (i = 1; i<=r; i++) { for(j = 1; j <= c; j++) { printf("Enter element for row %d column %d: ",i,j); scanf("%d",&a[i][j]); } printf("\n"); } //display of the matrix printf("The matrix is:\n"); for (i = 1; i<=r; i++) { for(j = 1; j <= c; j++) { printf("%d\t",a[i][j]); } printf("\n"); } //display of maximum minimum of each row printf("\n**The maximum minimum of each row of the matrix**\n"); for(i=1;i<=r;i++) { M=max(a,c,i); N=min(a,c,i); printf("\n The maximum value of %d th row %d\n",i,M); printf("\n The minimum value of %d th row %d\n",i,N); printf("\n"); } //finding transpose of the matrix for (i = 1; i <= r; i++) for( j = 1 ; j <= c ; j++ ) b[j][i] = a[i][j]; //display the the transpose of the matrix printf("Transpose of entered matrix:-\n"); for (i = 1; i <= c; i++) { for (j = 1; j <= r; j++) printf("%d\t",b[i][j]); printf("\n"); } getch(); } //end of main function //defining function for finding the minimum value int min(int a[30][30],int c,int i) { int j=c,m; if(c==1) { return a[i][j]; } else { m=min(a,c-1,i); return((a[i][j]<m)?a[i][j]:m); } } //defining function for finding the maximum value int max(int a[30][30],int c,int i) { int j=c,m; if(c==1) { return a[i][j]; } else { m=max(a,c-1,i); return((a[i][j]>m)?a[i][j]:m); } } output: 1 2 3 4 5 6 7 8 9 **The maximum minimum of each row of the matrix** The maximum value of 1 th row 3 The minimum value of 1 th row 1 The maximum value of 2 th row 6 The minimum value of 2 th row 4 The maximum value of 3 th row 9 The minimum value of 3 th row 7 Transpose of entered matrix:- 1 4 7 2 5 8 3 6 9
Tags:
C Program
0 comments