Search Your Query

Breaking

Sunday, July 7, 2019

Find The Maximum Number Using 2D Array


Find The Maximum Number Using 2D Array


Program Code:

#include<stdio.h>
#include<stdlib.h>
int main()
{
int **a,i,j,r,c,max,min;
printf("Enter the size of row and column\n");
scanf("%d%d",&r,&c);
a=(int**)malloc(r*sizeof(int));
for(i=0;i<c;i++)
{
a[i]=(int*)malloc(c*sizeof(int));
}
printf("Enter the elements\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
max=-32766;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(max<a[i][j])
{
max=a[i][j];
}
}
}
printf("Maximum number is-->%d\n",max);
return 0;

}


Hence, logic are same of 1d array

Input:

Enter the size of array
5
Enter the elements
12
47
10
65
89
30

Output:

Maximum number is-->89

No comments:

Post a Comment