Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]
Just for Practice 2 Additional [3-Jan-2018 to 10-Apr-2018]
Program ID- 1246
Given an nXn matrix with entries as numbers, write an algorithm and C program to print the maximum value in each row of the matrix.
Input Format:
Value of ‘n’
Element in first row first column
Element in first row second column
..
Element in the first row n-th column
Element in second row first column
Element in second row second column
..
Element in the second row n-th column
…
Element in nth row first column
Element in nth row second column
..
Element in nth row n-th column
Output Format:
Maximum value in the first row
Maximum value in the second row
…
Maximum value in the n-th row
Please Comment Working if the code worked to you
If you have other working codes please comment the codes enclosing with <pre> and </pre>
Example: <pre> Your Code </pre>
Input Format:
Value of ‘n’
Element in first row first column
Element in first row second column
..
Element in the first row n-th column
Element in second row first column
Element in second row second column
..
Element in the second row n-th column
…
Element in nth row first column
Element in nth row second column
..
Element in nth row n-th column
Output Format:
Maximum value in the first row
Maximum value in the second row
…
Maximum value in the n-th row
Please Comment Working if the code worked to you
If you have other working codes please comment the codes enclosing with <pre> and </pre>
Example: <pre> Your Code </pre>
Code: C++
#include<stdio.h>
int main()
{
int n,i,j;scanf("%d",&n);
int A[n][n];
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
scanf("%d",&A[i][j]);
}
}
for (i=0;i<n;i++)
{
int temp=0;
for (j=0;j<n;j++)
{
if (temp<A[i][j]){temp=A[i][j];}
}
printf("%d\n",temp);
}
}
int main()
{
int n,i,j;scanf("%d",&n);
int A[n][n];
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
scanf("%d",&A[i][j]);
}
}
for (i=0;i<n;i++)
{
int temp=0;
for (j=0;j<n;j++)
{
if (temp<A[i][j]){temp=A[i][j];}
}
printf("%d\n",temp);
}
}
NOTE: The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.
nice article for beginners.thank you.
ReplyDeleteC++ tutorial
java tutorial