Question

Construct a recursive definition for f(n) = floor(0/2) + floor(1/2) + … + floor(n/2), where the...

Construct a recursive definition for f(n) = floor(0/2) + floor(1/2) + … + floor(n/2), where the variables represent natural numbers.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ code:

#include<iostream>
#include<math.h>
using namespace std;

int func(double n){

if (n == 0){
return floor(n/2);
}
else{
return floor(n/2) + func(n-1);
}
}

int main(){
int n=10;
cout<<"f(n) for n = "<<n<<" is "<< func(n)<<"\n";

}

Screenshot of above code:

1 2 3 4 #include<iostream> #include<math.h> using namespace std; lint func (double n) { 7 8 9 10 11 if (n == 0) { return floo

Output:

f(n) for n = 10 is 25

Add a comment
Know the answer?
Add Answer to:
Construct a recursive definition for f(n) = floor(0/2) + floor(1/2) + … + floor(n/2), where the...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT