Computer Science, asked by drsagar3198, 2 days ago

you are given an array of 2*n non negative integers your task to tell whether the following array can be split into n pairs of 2 elements each auch that the aum of elements in each pair is odd in c language

Answers

Answered by samarthkrv
1

Answer:

#include <stdio.h>

int main()

{

   int arr[] = {1,4,5,6};

   int oddPairs = 0 , len = sizeof(arr)/sizeof(arr[0]) , index = 0;

       for(int i = 0; i < len; i++){

           if((arr[index]+arr[index+1]) % 2 == 1){

               oddPairs++;

               index+=2;

           }

       }

   if(len/2 == oddPairs){

       printf("the following array can be split into n pairs of 2 elements each such that the sum of elements in each pair is odd");

   }

   else{

       printf("the following array can not be split into n pairs of 2 elements each such that the sum of elements in each pair is odd");

   }

   return 0;

}

Explanation:

Similar questions