1. Write a program with a function that takes two int ... - Google Sites

1 downloads 94 Views 82KB Size Report
Write and test the a function SQUARE(int n) that determines whether the given integer is a square number. The output wil
Exercise 03

Page 1 of 2

1. Write a program with a function that takes two int parameters, adds them together, and then returns the sum. The program should ask the user for two numbers, then call the function with the numbers as arguments, and tell the user the sum. 2. Basically the same as Prob 1, but this time, the function that adds the numbers should be void, and takes a third, pass by reference parameter; then puts the sum in that. 3. Using permutation function, write a program that calculates the following expression: P(n,k) = (n!) / (n-k)! 4. Using permutation function, write a program that calculates the following expression which is more effective than the previous one to find the permutation of P: P(n,k) = n . (n-1) . (n-2) . … … … (n-k+2) (n-k+1) 5. Using combination function, write a program that calculates the following expression: C(n,k) = (n!) / {k! (n-k)!} 6. Using functions, write a program that calculates the following expression: C(n,k) = P (n,k) / k! 7. Following Triangle is known as Pascal’s Triangle. 1

1 1 1 1

1 7

6

1 5 21

4 15

1 3 10 35

2 6 20

1 3 10 35

1 4 15

1 5 21

1 6

1 7

1 1

Each number in this Triangle is one of the combinations C(n,k); where n is row number and k is column number. For Example, C(6,2) = 15. Write a program that uses a comb() function to print the triangle down to row number 12. Hints: Use setw() function to fix the column width. Run the following program to see the function of setw(). #include // defines setw() #include using namespace std; int main() { for (int x=1; x

Suggest Documents