Saturday, August 18, 2018

COMPARE 2 ARRAYS USING FUNCTION


  • Problem Description

    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.
  • CODING ARENA
  • #include<stdio.h>
    int main()
    {
      int a[100],n,i,b[100],c=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])
          c=1;
      }
      if(c==1)
        printf("no");
      else
        printf("yes");
      return 0;
    }

      
  • Test Case 1

    Input (stdin)
    5
    
    2 3 6 8 -1
    
    2 3 6 8 -1
    
    
    Expected Output
    yes
  • Test Case 2

    Input (stdin)
    5
    
    2 3 6 8 -1
    
    2 3 6 8 10
    
    
    Expected Output
    no

No comments:

Post a Comment