Canna

Thursday, 27 September 2018

Compare 2 arrays

  • 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.
  • 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
  • Program
  • #include <stdio.h>
    int main()
    {
      int i,j,n,a[50],b[50],count=0;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
        scanf("%d ",&a[i]);
      scanf("%d ",&b[i]);
    }
      for(i=0;i<n;i++)
      {
        for(j=0;j<n;j++)
          if(a[i]==b[j])
            count=count+1;
      }
      if(count==n)
      printf("yes");
      else
      printf("no");
      return 0;
    }

No comments:

Post a Comment

Note: only a member of this blog may post a comment.