Computer Science, asked by dhruvgupta15, 7 months ago

10. Pu412)
2. a. Write definition of a method/function AddOddEven (VALUES) to display sum of odd
and even values separately from the list of VALUES.
3
For example:
If the VALUES contain [15, 26, 37, 10, 22, 13]
The function should display
Even Sum:58
Odd Sum: 65​

Answers

Answered by lekhanar47
4

65 58 what's this question

Answered by mad210203
4

Program is given below.

Explanation:

#include <stdio.h>

AddOddEven(int a[],int n)

{

   int i,even_sum=0,odd_sum=0;

   for(i=0;i<n;i++)

   {

       if(a[i]%2==0)

       even_sum=even_sum+a[i];

       else

       odd_sum=odd_sum+a[i];

   }

   printf("Even Sum = %d",even_sum);

   printf("\nOdd Sum = %d\n",odd_sum);

}

int main() {

   int num[10],n,i;

   printf("Enter the number of elements: ");

   scanf("%d",&n);

   printf("Enter the elements: \n");

   for(i=0;i<n;i++)

   {

       scanf("%d",&num[i]);

   }

   printf("\n");

   AddOddEven(num,n);

   return 0;

}

Refer the attached image for the output.

Attachments:
Similar questions