1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <stdio.h>
#include <conio.h>
#define max 5
void main(){
int m[max][max],inpc,inpr,i,j;
int firstlow=0,firsthigh=0,secondlow=0,secondhigh=0,xcor=0,ycor=0,hxcor=0,hycor=0;
clrscr();
printf("Enter number of columns: ");
scanf("%d",&inpc);
printf("\nEnter number or rows: ");
scanf("%d",&inpr);
m[inpc][inpr]=m[max][max];
printf("\nYour matrix is a %d by %d matrix.",inpc,inpr);
printf("\n\nEnter value of matrix: \n");
for(i=0;i<inpc;i++){
for(j=0;j<inpr;j++){
scanf("%d",&m[i][j]);
}
}
printf("\nYour matrix list: \n");
for(i=0;i<inpc;i++){
for(j=0;j<inpr;j++){
printf("%d ",m[i][j]);
}
printf("\n");
}
firstlow=m[0][0];
firsthigh=m[0][0];
for(i=0;i<inpc;i++){
for(j=0;j<inpr;j++){
secondlow=m[i][j];
if(secondlow < firstlow){
firstlow=secondlow;
xcor=i;
ycor=j;
}}}
for(i=0;i<inpc;i++){
for(j=0;j<inpr;j++){
secondhigh=m[i][j];
if(secondhigh > firsthigh){
firsthigh=secondhigh;
hxcor=i;
hycor=j;
}}}
printf("Highest value in the matrix is %d",firsthigh);
printf("Coordinates are col %d row %d",hxcor,hycor);
printf("Lowest value in the matrix is %d",firstlow);
printf("Coordinates are col %d row %d",xcor,ycor);
getch();
}
|