Code For Alls..!

get the code!!

Sunday, 23 July 2017

2D Matrix Modification 001

A Matrix has R rows and C columns. Get the matrix as input and multiply the value in the cells of the matrix by a value E if it is even and multiply it by a value F if it is odd.
Input Format:
The first line contains R.
The second line contains C.
Next R lines containing the elements of the matrix with each column value seperated by a space.
R+3 line contains E.
R+4 line contains F.

Output Format:
R lines containing the elements of the revised matrix with each column value seperated by a space.
Boundary Conditions:
1 <= R <= 100
1 <= C <= 100
1 <= E,F <= 100
Example Input/Output 1:
Input:
3
3
1 2 3
1 2 3
1 2 3
2
3
Output:
3 4 9
3 4 9
3 4 9
Example Input/Output 2:
Input:
4
5
12 19 16 18 12
2 12 14 5 12
8 3 17 4 19
18 11 5 14 9
2
5
Output:
24 95 32 36 24
4 24 28 25 24
16 15 85 8 95
36 55 25 28 45
C code:
#include<stdio.h>

 #include <stdlib.h>

int main()
{

int a[100][100],i,j,r,c,o,e;

scanf("%d%d",&r,&c);

for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);

scanf("%d%d",&e,&o);

for(i=0;i<r;i++)
{
    for(j=0;j<c;j++)
{
if(a[i][j]%2==0)

printf("%d ",a[i][j]*e);

else

printf("%d ",a[i][j]*o);
}
printf("\n");
}

}

No comments:

Post a Comment