Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a function named oddSum. This function will return the sum of every odd value in the array. The function has two parameters: int arr[],
Create a function named oddSum. This function will return the sum of every odd value in the array.
The function has two parameters:
- int arr[], an array of integers
- int size, the size of the array.
Use the following function definition:
// This is what I have but it keeps adding numbers that are not an odd value. It will just add every number in the array instead of adding odd values only.
int oddSum(int arr[], int size){
int totalSum = 0; if (size <= 0) return 0; else for (int i = 0; i < size; i++) { if (arr[i % 2 != 0]) totalSum = totalSum + arr[i]; } return arr[0] + oddSum(arr + 1 , size - 1);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started