Write C program to find the
maximum number from the nxm
array.
#include <stdio.h>
#include <stdlib.h>
int main() {
int row;
int col;
int i, j;
int number;
int maximumNumber;
printf("Enter number of rows: ");
scanf("%d",&row);
printf("Enter number of columns: ");
scanf("%d",&col);
int *matrix = (int *)malloc(row * col * sizeof(int));
for (i = 0; i < row; i++){
for (j = 0; j < col; j++){
printf("Enter number [%d][%d]: ",i,j);
scanf("%d",&number);
*(matrix + i*col + j) = number;
}
}
maximumNumber=matrix[0,0];
printf("The matrix elements are:\n");
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
number=*(matrix + i*col + j);
printf("%d ",number);
if(maximumNumber<number){
maximumNumber=number;
}
}
printf("\n");
}
free(matrix);
printf("\nMaximum number is: %d\n\n",maximumNumber);
getchar();
getchar();
return 0;
}
Comments
Leave a comment