Question

A function called combthat takes twoparameters: n,rand returns the value of n choose r.Sample command =>...

A function called combthat takes twoparameters: n,rand returns the value of n choose r.Sample command => output:(display (comb 6 3))=> 20Hint: The value of n choose r, C(n,r),is recursively defined as:C(n,r) = n, if r =1= 1, if r = n or r = 0= C(n-1,r-1) + C(n-1, r), otherwise

program language Scheme

Homework Answers

Answer #1

import java.util.*;

class Combinatorics {

    static int Solve(int n, int r)

    {

        if (r == 0 || r == n)

            return 1;

         

        return Solve(n - 1, r - 1) +

Solve(n - 1, r);

    }

     

   public static void main(String[] args)

   {

        int n = 5, r = 2;

        System.out.println(Solve(n, r));

    }

}

Know the answer?
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
Similar Questions
A function called sum that takes n as a parameter and then returns the value of...
A function called sum that takes n as a parameter and then returns the value of 13+23+33+...+n3.Sample command => output:(display (sum 5)) => 225
MATLAB: Write a function called matrix_problem1 that takes a matrix A of positive integers as its...
MATLAB: Write a function called matrix_problem1 that takes a matrix A of positive integers as its sole input. If the assumption is wrong, the function returns an empty matrix. Otherwise, the function doubles every odd element of A and returns the resulting matrix. Notice that the output matrix will have all even elements. For example, the call B = matrix_problem([1 4; 5 2; 3 1], will make B equal to [2 4; 10 2; 6 2]. The function should work...
Define a function called ngram_list() that takes a filename and a positive integer n representing the...
Define a function called ngram_list() that takes a filename and a positive integer n representing the number of characters to be displayed on each line (but don't actually display anything in this function — so no print() in this function). The function should return a list of strings, consisting of the contents of the file split into chunks n characters long. If there is an error working with the file, the function should return an empty list. For example, using...
Write a function called matches that takes two int arrays and their respective sizes, and returns...
Write a function called matches that takes two int arrays and their respective sizes, and returns the number of consecutive values that match between the two arrays starting at index 0. Suppose the two arrays are {3, 2, 5, 6, 1, 3} and {3, 2, 5, 2, 6, 1, 3} then the function should return 3 since the consecutive matches are for values 3, 2, and 5. in C++ Im confused how to start this, any hints are great and...
Using C programming Create a function called printMenu( ) with the following properties: Has no function...
Using C programming Create a function called printMenu( ) with the following properties: Has no function inputs or output. Prints the following menu to the screen: 1. Enter user name. 2. Enter scores. 3. Display average score. 4. Display summary. 5. Quit Create a function called printLine( ) with the following properties: Takes as input a char Takes as input an integer corresponding to the number of times to print the character Has no function output. For example, if we...
For any integer n > 0, n!(n factorial) is defined as the product n * n...
For any integer n > 0, n!(n factorial) is defined as the product n * n - 1 * n − 2 … * 2 * 1. And 0! is defined to be 1 Create function that takes n as input and computes then returns the accurate value for: n!= n * n - 1 * n − 2 … * 2 * 1 prompt the user to enter an integer n, call functions to compute the accurate value for...
python pls Create function math_life() this function takes one or more argument. If this function called...
python pls Create function math_life() this function takes one or more argument. If this function called with no argument, raise typeError. The math_life() function returns to a function defined inside. this will take a one argument. For the second argument, it will calculate second function passed to math_life(). You should assume that the math_life() passed x functions, when it called the x times it will calculate the xth function passed to math_life() arguments when it called x+1 time it again...
Write the recursive version of the function decimal which takes in n, a number, and returns...
Write the recursive version of the function decimal which takes in n, a number, and returns a list representing the decimal representation of the number. def decimal(n): """Return a list representing the decimal representation of a number. >>> decimal(55055) [5, 5, 0, 5, 5] >>> decimal(-136) ['-', 1, 3, 6] """
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them.         [0.5 mark] (BY USING C PROGRAM)
Write a function called TaylorSin.m that takes as input an array x, and positive integer N,...
Write a function called TaylorSin.m that takes as input an array x, and positive integer N, and returns the Nth Taylor polynomial approximation of sin(x), centered at a = 0. The first line of your code should read function s = TaylorSin(x,N) HINT: in computing k!, use kfact = k*(k-1)*kfact since you are counting by 2
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT