Question
//You need to fix the following code so that it reports the correct sum of all multiples of 5 from 0 to n. //Make sure
//You need to fix the following code so that it reports the correct sum of all multiples of 5 from 0 to n. //Make sure to correct the code with a minimum number of changes (i.e: do not add new lines of code - if possible). ================= #include using namespace std; int sum (int num){ return (num ==0 ) ? 1: num + sum (num - 5); } int main (){ cout << sum (16) << endl; } ================== //Test cases: //when n= 10 the correct sum is 15 //when n=15 the correct sum is 30 //when n= 12 the correct sum is 15 //when n=18 the correct sum is 30 //when n=19 the correct sum is 30 //when n=23 the correct sum is 50
in c++
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