Question

In: Computer Science

Module/Week 2 ASSIGNMENT (INPUT/OUTPUT) The number of permutations of a set of n items taken r...

Module/Week 2 ASSIGNMENT (INPUT/OUTPUT)
The number of permutations of a set of n items taken r at a time is given by the following
formulan!/r !(n- r )!: where n! is the factorial of n, r! is the factorial of r, and (n-r)! is the
factorial of the result of n-r. The factorial of a number n can be solved using the following
formula: n!=e-n nn √ 2πn.
If there are 18 people in your class and you want to divide the class into programming teams of 3
members, you can compute the number of different teams that can be arranged using this formula
(n!/r !(n- r )!).
Write a C++ program that determines the number of potential team arrangements. You will need
to use the double type for this computation. Use the Lab Template you set-up last week, proper
formatting, and appropriate comments in your code. The output must be labeled clearly and
formatted neatly.
Submit C++ Programming Assignment 2 by 11:59 p.m. (ET) on Monday of Module/Week 2

Solutions

Expert Solution

Hey , I dont know about lab template if you want to give please comment below

#include<bits/stdc++.h>
#include<numeric>
using namespace std;
int main()
{
        double n,r,num;
        cout<<"Enter the total students and number of children in one group"<<endl;
        cin>>n>>r; // taking input total student and number of children in one team
        double v=n-r; // declaring v=n-r
        double ans;
        for(int i=n-1;i>=1;i--)
        {
                n*=i; // finding factorial n! like n*(n-1)*(n-2)*...*1 
        }
        for(int i=r-1;i>=1;i--)
        {
                r*=i; // finding factorial r! like r*(r-1)*(r-2)*...*1
        }
        for(int i=v-1;i>=1;i--)
        {
                v*=i;// finding factorial v! like v*(v-1)*(v-2)*...*1
        }
        // our formula is n!/(r!(v)!) where v=n-r
        ans=n/r;
        ans=ans/v;
        cout<<"NUMBER OF ARRANGEMENTS "<<ans<<endl;
}

This is the basic code to do it. You can also find factorial by recursion if you want i can do this question by recursion.

Below is the screenshot of above code.

Please upvote

If face any problem comment below.


Related Solutions

Find the number of r-permutations of the multiset {∞?1, ∞?2, … , ∞??} such that in...
Find the number of r-permutations of the multiset {∞?1, ∞?2, … , ∞??} such that in every such permutation each type of an element of the multiset appears at least once. (You do not need to provide a short answer. Assume r ≥ n.)
About finding the number of permutations Let there be n pairs of 2*n students : (1,...
About finding the number of permutations Let there be n pairs of 2*n students : (1, 2) , (3, 4), (5, 6) ... (2n-1 , 2n). We want to find the number of arrangements of students which the pair are not adjacent. In other words, for (2*i) th student, the (2*i -1) th student should not be in his front or back. For example, think of case of n=2. In this case, (1, 4, 3, 2) is not appropriate for...
R= Ro(1/2)n n= number of half lifetimes= t/t1/2 (a)n= 2/2= 1 R= Ro(1/2)n R=3000(1/2)1 R= 1500...
R= Ro(1/2)n n= number of half lifetimes= t/t1/2 (a)n= 2/2= 1 R= Ro(1/2)n R=3000(1/2)1 R= 1500 counts/sec (b)n= 6/2= 3 R= Ro(1/2)n R=3000(1/2)3 R= 375 counts/sec (c) n= 10/2= 5 R= Ro(1/2)n R=3000(1/2)5 R= 93.75 counts/sec (d) n= 20/2= 10 R= Ro(1/2)n R=3000(1/2)10 R= 2.93 counts/sec What is the mean life of this nucleus? f. Suppose that the Geiger counter detects 10% of all the radioactive decays. What is the total number of radioactive nuclei at time t = 0?...
x[n] is the input of a system and y[n] is the output of the system. The...
x[n] is the input of a system and y[n] is the output of the system. The relationship between the input and output is the following: y[n] = x[n]u[n+1] a) Is the system memoryless? Just yes or no is sufficient. b) Is this system causal? Just yes or no is sufficient. c) Is the system linear? Just yes or no is sufficient. d) Is the system time invariant? Justify. e) Is the system BIBO stable? Justify. f) Is the system invertible?...
A Mystery Algorithm Input: An integer n ≥ 1 Output: ?? Find P such that 2...
A Mystery Algorithm Input: An integer n ≥ 1 Output: ?? Find P such that 2 P is the largest power of two less than or equal to n. Create a 1-dimensional table with P +1 columns. The leftmost entry is the Pth column and the rightmost entry is the 0th column. Repeat until P < 0 If 2 P ≤ n then put 1 into column P set n := n − 2 P Else put 0 into column...
Determine the number of permutations of {1,2,3,...,n-1,n} where n is any positive integer and no even...
Determine the number of permutations of {1,2,3,...,n-1,n} where n is any positive integer and no even integer is in its natural position.
** Number 2 implemented in R (R Studio) ** Set up the Auto data: Load the...
** Number 2 implemented in R (R Studio) ** Set up the Auto data: Load the ISLR package and the Auto data Determine the median value for mpg Use the median to create a new column in the data set named mpglevel, which is 1 if mpg>median and otherwise is 0. Make sure this variable is a factor. We will use mpglevel as the target (response) variable for the algorithms. Use the names() function to verify that your new column...
A Mystery Algorithm Input: An integer n ≥ 1 Output: ?? Find P such that 2^p...
A Mystery Algorithm Input: An integer n ≥ 1 Output: ?? Find P such that 2^p is the largest power of two less than or equal to n. Create a 1-dimensional table with P +1 columns. The leftmost entry is the Pth column and the rightmost entry is the 0th column. Repeat until P < 0 If 2^p≤n then put 1 into column P set n := n - 2^p Else put 0 into column P End if Subtract 1...
Java assignment Get a file name fname for output • Get number of data (numbers) (N)...
Java assignment Get a file name fname for output • Get number of data (numbers) (N) you want to process from the user • Get N numbers from the users through keyboard and store them in an array • Write the numbers into the file fname
Module 07 Written Assignment - C-Diff Your written assignment for this module should be a 1-2...
Module 07 Written Assignment - C-Diff Your written assignment for this module should be a 1-2 page paper (not including title page and reference page) that describes the following: -You are caring for a patient with c-diff as part of your workload assignment. Discuss what c-diff is and how it is transmitted (how you can get it)? -What actions will you take as a nurse to protect yourself and the other patients on the unit when taking care of your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT