Compare 2 arrays
Write a program to find whether 2 arrays are the same.
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 next ‘n’ integers correspond to the elements in the second array.Assume that the maximum value of n is 15.
Output Format:
Print yes if the 2 arrays are the same. Print no if the 2 arrays are different.
Sample Input 1:
5
2
3
6
8
-1
2
3
6
8
-1
Sample Output 1:
yes
Sample Input 2:
5
2
3
6
8
-1
2
3
6
8
10
Sample Output 2:
no
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("no");
else
printf("yes");
return 0;
}
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("no");
else
printf("yes");
return 0;
}
No comments