Saturday, April 27, 2019

Compatible Arrays using Functions

Problem Description

Two arrays are said to be compatible if they are of the same size and if the ith element in the first array is greater than or equal to the ith element in the second array for all i.Write a program to find whether 2 arrays are compatible or not.

Input Format:

Input consists of 2n+1 integers. The first integer corresponds to n , the size of the array. The next n integers correspond to the elements in the first array. The last n integers correspond to the elements in the second array. Assume that the maximum value of n is 15.
Test Case 1

Input (stdin)
5

2 3 6 8 1

1 1 1 1 1

Expected Output

Compatible
Test Case 2

Input (stdin)
5

2 3 6 8 1

1 1 1 2 2

Expected Output

Incompatible

Solution

#include<stdio.h>
int main(){
int n,a[20],b[20],i,flag=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++){
scanf("%d",&b[i]);
if(a[i]<b[i])
flag=1;
}
if(flag)
printf("Incompatible");
else
printf("Compatible");


return 0;
}

No comments:

Post a Comment

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...