Sum of even elements and sum odd elements in an array using function

#include<stdio.h>

int oddevensum(int a[], int size)
{
    int odd=0 , even=0 , i;
    for(i=0;i<size;i++)
    {
        if(a[i]%2==0)
            even=even+a[i];
        else
            odd=odd+a[i];
    }

   
    printf("  SUM of EvEN numbers : %d",even);
    printf("  \n SUM of Odd numbers : %d",odd);

}

int main()
{
    int size , i , a[100] , sumeven=0,sumodd=0;

    printf(" Enter the size of the array elements : ");
    scanf("%d",&size);

    printf("\n Enter the array elements : ");
    for(i=0;i<size;i++)
    {
        scanf("%d",&a[i]);
    }
    sumeven=oddevensum(a,size);
    sumodd=oddevensum(a,size);

    //printf(" \n The sum of the even numbers : %d",sumeven);
    //printf(" \n The sum of the odd numbers : %d",sumodd);

    return 0;
}

OUTPUT :





For Other Programs Visit The WebSite:-   https://www.techapurba.com/

Follow Me On Social Media :-





For tech related videos visit my other website :- https://apurbatechinfo.blogspot.com/



Post a Comment

0 Comments