difference of odd sum and even sum in the array

Difference of odd sum and even sum in the array

#include<stdio.h>
int findOddEvenDifference(int n,int a[])
{
    int esum=0,osum=0,i;
for(i=0;i<n;i++)
    {
        if (a[i]%2==0)
        esum=esum+a[i];
        else
        osum=osum+a[i];
    }
    return osum-esum;

int main() {
    int n,a[100],i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    printf("%d",findOddEvenDifference(n,a));
}

Sample input and output

5
10 11 7 12 14

No comments:

Post a Comment