Question

C Programming: Write a function that takes in an array of integers and an integer containing...

C Programming:

Write a function that takes in an array of integers and an integer containing the count of elements, then have it returns the sum of all the even values inside the array.

Homework Answers

Answer #1

Code:

#include<stdio.h>

int sum_even(int a[], int size);
 
void main()
{
 int Size, i, a[10];
 int result = 0;
 clrscr();
 
 printf("Please Enter the Size of an Array :  ");
 scanf("%d", &Size);
 
 printf("\nPlease Enter the Array Elements\n");
 for(i = 0; i < Size; i++)
 {
   scanf("%d", &a[i]);
 }
 
 result = sum_even(a, Size);
 printf("\n The sum of Even Numbers in this Array = %d ", result);
 getch();
}

int sum_even(int a[], int size) {
   int j;
   int sum = 0;
   for(j=0; j<size; j++)
   {
   if(a[j]%2==0)
   {
      sum=sum+a[j];
   }
   }
   return sum;
 }

Screenshot of output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
C programming Write a function that takes in a 2D char array (string array) and return...
C programming Write a function that takes in a 2D char array (string array) and return a 1D char array with all the elements connected together Hint: strlen(-char*-) //returns the length of a string strcat(-char* accum-, something to add) //works like string+= in java
Write a function makeDoubles in c++, that takes an integer parameter called size and: allocates a...
Write a function makeDoubles in c++, that takes an integer parameter called size and: allocates a new array of that many double's initializes all elements to be 0 returns this array
C programing Write a function that takes in an integer as input and returns an integer...
C programing Write a function that takes in an integer as input and returns an integer array of zeros.
Write a function that takes an array of integers and its size as parameters and prints...
Write a function that takes an array of integers and its size as parameters and prints the two largest values in the array. In this question, the largest value and the second largest value cannot be the same, even if the largest value occurs multiple times. In the first sample, the two largest values are 9 and 8 (even though the value 9 appears twice). In the second sample, all the values are equal and the program recognizes this by...
(C++) Write a function called triple that takes an array of integers as a parameter as...
(C++) Write a function called triple that takes an array of integers as a parameter as well as the length of the array. It should triple each value in the array. The function should not return anything. (Note that the contents of the array WILL be modified.)
In C Not C++ write a function that takes in the reference of an int array...
In C Not C++ write a function that takes in the reference of an int array and return the value -1 if sum is odd, and 1 if the sum is even.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.