UNIFORMITY MATRIX
Problem Description
Uniformity matrix is a matrix in which all the elements in the matrix are either completely even or completely odd.
Write a C program to find whether a given matrix is a uniformity matrix or not.
Input Format:
The input consists of (n*n+1) integers. The first integer corresponds to the number of rows/columns in the matrix. The remaining integers correspond to the elements in the matrix. The elements are read in rowwise order, first row first, then second row and so on. Assume that the maximum value of m and n is 5.
Output Format:
Print yes if it is a uniformity matrix. Print no if it is not a uniformity matrix.
CODING ARENA
#include <stdio.h>
int main()
{
int a[100][100];
int n=0,i,j,cnt=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]%2==0)
cnt++;
}
}
if(cnt==n*n||cnt==0)
{
printf("yes");
}
else
{
printf("no");
}
return 0;
}
Test Case 1
Input (stdin)3
4 5 1
5 4 3
2 3 4
Expected Output
no
Test Case 2
Input (stdin)3
1 3 5
9 1 3
1 3 5
Expected Output
yes
What if the element in the matrix is 0
ReplyDelete