Question-Write a program to pick up the largest number from any 5 row
by 5 column matrix.
Solution-An easy Question and Again easily generalizable using macro definitions.
#include <stdio.h>
#include <stdlib.h>
#define m 5
#define n 5
int main()
{
int arr[m][n],i,j,k,num;
printf("Enter the elements of the array\n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
scanf("%d",&arr[i][j]);
}
num=arr[0][0];
for(i=0;i<=m-1;i++)
{
for(j=1;j<=n-1;j++)
{
if(num<arr[i][j]) /*Individually Comparing and Exchanging the Values */
{
k=num;
num=arr[i][j];
arr[i][j]=k;
}
}
}
printf("The largest number of the array is %d\n",num);
getch();
}
by 5 column matrix.
Solution-An easy Question and Again easily generalizable using macro definitions.
#include <stdio.h>
#include <stdlib.h>
#define m 5
#define n 5
int main()
{
int arr[m][n],i,j,k,num;
printf("Enter the elements of the array\n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
scanf("%d",&arr[i][j]);
}
num=arr[0][0];
for(i=0;i<=m-1;i++)
{
for(j=1;j<=n-1;j++)
{
if(num<arr[i][j]) /*Individually Comparing and Exchanging the Values */
{
k=num;
num=arr[i][j];
arr[i][j]=k;
}
}
}
printf("The largest number of the array is %d\n",num);
getch();
}
No comments:
Post a Comment