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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!