C Program For MIN and MAX element in 2D array (Matrix)

#include<stdio.h>
#include<conio.h>
void main()
{
int min,max,i,j,a[10][10],n;
clrscr();

printf("\nenter the Matrix elements:");

for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nelements inserted are:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
 printf("%d  ",a[i][j]);
}
printf("\n");
}
min=a[0][0];
max=a[0][0];
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{

 if(a[i][j]<min)
  min=a[i][j];
 if(a[i][j]>max)
  max=a[i][j];
}
}
printf("\n min is : %d and Max is :%d ",min,max);
getch();
}


Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment