Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

--- stdio.h C program --- Problem 1. Permutation and Combination (30 points) Suppose, there are n objects and you are given the option to choose

--- stdio.h C program ---

image text in transcribed

Problem 1. Permutation and Combination (30 points) Suppose, there are n objects and you are given the option to choose r objects from them. If the order of choice matters, it is called Permutation. Otherwise, it is known as Combination. Given the values of n and r, the number of permutations, P(n, r) and combinations, C(n, r) are determined using the following formula P(n,r) - C(n,r) - where, n!-1x 2 x 3 x x (n -1) x n Write a program that takes n and r as input and calculates the corresponding number of permutations and combinations. n and r should be non-negative integers and ner. If user gives illegal inputs, your code should print a proper error message. You are required to write a user- defined function to calculate the factorial. Call the function from main function to properly calculate the permutation and combination values. For this problem, recursion is not necessary Sample Input and Output: (Your code should print the red texts on the screen. Black texts are sample user inputs) Sample Input Sample Output n: 12 r: n: r: n: r: n: r: Number of Permutation: 79833600 Number of Combination: 220 Number of Permutation: 720 Number of Combination: 1 Invalid Input Invalid Input Number of Permutation:1 Number of Combination: 1 r

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions