Question

Main topic and problems for the final project The main purpose of the project is to introduce you how to use a computer as a

Discrete Math and Computer Science
I need help with #2 the programming part is in C++ Thank you!

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

Answer 2:

(a)

/**
 * Program for Left Hand Side
 */

#include <iostream>
#include <cmath>

using namespace std;

long long factorial(long long n){
    if(n <= 1)
        return 1;
    return n * factorial(n - 1);
}

long long sigma(long long n){
    long long sum = 0;
    for(int k = 0; k <= floor(n/2); k++){
        sum += factorial(n - k)/(factorial(k) * factorial(n - 2*k));
    }
    return sum;
}

int main(){
    int n = 20;
    cout << "Left Hand Side for n = " << n << " = " << sigma(n) << endl;
    return 0;
}

(b)

/**
 * Program for Right Hand Side
 */

#include <iostream>

using namespace std;

long long F(int n){
    if(n <= 1)
        return n;
    return F(n - 1) + F(n - 2);
}

int main(){
    int n = 20;
    int t = n + 1;
    cout << "Right Hand Side for t = " << t << " = " << F(t) << endl;
    cout << "Here t = n + 1" << endl;
    return 0;
}

(c)

For n = 20

Output from (a)

untitled2X C: \Users Shubham CLion Projects\untitled2 \Cmake-build-debug\untitled2.exe Left Hand Side for n = 20 = 10946 Proc

t = 21 because t = n + 1 and n = 20

Output from (b)

C:\Users\Shubham\CLionProjects \untitled2\ cmake-build-debug\untitled2.exe Right Hand Side for t= 21 = 10946 Here t n + 1 Pro

Add a comment
Know the answer?
Add Answer to:
Discrete Math and Computer Science I need help with #2 the programming part is in C++ Thank you! Main topic and prob...
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
  • Main topic and problems for the final project The main purpose of the project is to introduce you how to use a in a...

    Main topic and problems for the final project The main purpose of the project is to introduce you how to use a in an computer as a research tool Introductory Discrete Mathematics. In this project you will be asked to show how the Fibonacci sequence {Fn} is related to Pascal's triangle using the following identities by hand for small and then by computers with large n. Finally, to rove the identity by mathematical arguments, such as inductions or combinatorics. I...

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