integer odd even

problem: (courtesy:101cproblems.com)
Take an array of integer data type of size 5. Scan the values from the user. Now print the output like the following one-
Values in array: 10 25 20 15 30
Sum of odd values: 40
Sum of even values: 60

code:

#include<stdio.h>
int main()
{
    int sume=0,sumo=0;
    int i,a[5];
    for(i=0; i<5; i++)
    {
        scanf("%d",&a[i]);
        printf("%d\t\n",a[i]);
        if(a[i]%2==0)
        {
            sume=sume+a[i];
        }
        if(a[i]%2!=0)
        {
            sumo=sumo+a[i];
        }
    }
    printf("sum of even values=%d\n",sume);
    printf("sum of odd values=%d",sumo);
    return 0;
}

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *