Assuming that the following integer array ArrayInts [] = {54, 152, 99, - 8, 3, 1
ID: 3865378 • Letter: A
Question
Assuming that the following integer array ArrayInts [] = {54, 152, 99, - 8, 3, 19, - 11, 260, 27, - 4, 10, 12, 15, 58, 480, 60}: is stored in the memory. Write a complete C language program that: computes the sum of all even integers in the array and displays the result on the console, computes the sum of all odd integers in the array and displays the result on the console, and Searches the array for the target value of the sum of all odd integers using Binary Search. If the target value was found within the array, a message indicating array index at which the target value was found should be displayed on the console otherwise "Target was not found" should be displayed.Explanation / Answer
#include <stdio.h>
// C program to return sum of even elements in an array of size n
int main()
{
unsigned int ArrayInts[] = {54,152,99,-8,3,19,-11,260,27,-4,10,12,15,58,480,60};
int size = sizeof(ArrayInts)/sizeof(arr[0]);
unsigned int sumeven=0,sumodd=0;
//running loop for the value of each element
for (int i = 0; i < size; i++)
{
//checking if the element is even or odd
if(ArrayInts[i]%2==0)
{
sumeven += ArrayInts[i];
}
else
{
sumodd += ArrayInts[i];
}
}
printf("Sum of even nmuber in the given array is %d ", sumeven);
printf("Sum of even nmuber in the given array is %d ", sumodd);
return 0;
}