Even or Odd Indices Program in C

Frenz i got this program in a Programming round of an interview process

(In C Language)

Write a function such that it has to take two arguments an array and its length and it should return the
Number of even Numbers at even indices and odd Numbers at odd Indeces
Sample Input:
arr[]={1,3,4,5,6,7,9}
Count=5
Explanation:
3 is odd and at odd index i.e, 1
4 is even and at even index i.e,2
5 is odd and at odd index i.e,3
6 is even and at even index i.e,4
7 is odd and at odd index i.e,5


Try to solve it and write your code in comments...
Program'll be updated tomorrow.........

Program:

int getCount(int arr[],int length)
  {
    int count=0,i;
    for(i=0;i<length;i++)
     {
       if(i%2==a[i]%2)
         {
           count++;
         }
     }
    return count;
  }


Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment