greatest element of given matrix
#include<stdio.h>
#include<conio.h>
main()
{
int a[5][5],m,n,i,j,big;
clrscr();
printf("\n enter the no. of rows of the matrix:");
scanf("%d",&m);
printf("\n enter the no. of columns of the matrix:");
scanf("%d",&n);
for(i=0;i<m;i++) /* input the elements */
for(j=0;j<n;j++)
{
printf("\n enter the A[%d][%d] element:",i+1,j+1);
scanf("%d",&a[i][j]);
}
if(m==n) /* check whether square matrix or not */
printf("\n The given matrix is a square matrix and ");
else
printf("\n The given matrix is not a square matrix and ");
printf("\n The elements of the given matrix are:");
for(i=0;i<m;i++) /* display the matrix */
{
printf("\n");
for(j=0;j<n;j++)
printf("\t %d",a[i][j]);
}
big=a[0]; /* logic to find the greatest element */
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(a[i][j]>=big)
big=a[i][j];
printf("\n biggest element in the matrix=%d",big); /* print the greatest element */
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int a[5][5],m,n,i,j,big;
clrscr();
printf("\n enter the no. of rows of the matrix:");
scanf("%d",&m);
printf("\n enter the no. of columns of the matrix:");
scanf("%d",&n);
for(i=0;i<m;i++) /* input the elements */
for(j=0;j<n;j++)
{
printf("\n enter the A[%d][%d] element:",i+1,j+1);
scanf("%d",&a[i][j]);
}
if(m==n) /* check whether square matrix or not */
printf("\n The given matrix is a square matrix and ");
else
printf("\n The given matrix is not a square matrix and ");
printf("\n The elements of the given matrix are:");
for(i=0;i<m;i++) /* display the matrix */
{
printf("\n");
for(j=0;j<n;j++)
printf("\t %d",a[i][j]);
}
big=a[0]; /* logic to find the greatest element */
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(a[i][j]>=big)
big=a[i][j];
printf("\n biggest element in the matrix=%d",big); /* print the greatest element */
getch();
}
No comments:
Post a Comment