Question

In Probability, number ofcombinations (sometimes referred to as binomial coefficients) ofn times taken r at a time is written as C (n.r) = | | = . If an order conscious subset of r times taken from a set of n times- the permutations, it is written as P(n, r) = . Both cases, r n 1. n! r r(nr)! n! Create a script that will prompt the user to type in values for n and r , then calculate C (n,r) and P(n,). After the display of the result, the user should be prompted as well whether shehe wants to repeat the process or not. Requirements 1) The user should be prompted 2 times for n and r 2) Check whether r S n. If this condition is not satisfied, warn the user to type in 3) Create a user defined function that computes the Clo.r). (This user defined function 4) 5) Store result of Cln.land Pín) in an array. appropriate values for r and n, AGAIN should take 2 arquments and return the numerical result of the Clo.r) Create a user defined function that computes the Pin ) (This user defined function should take 2 arquments and return the numerical result of the P(n,r).) After the display of the result, the user should be prompted as well whether she he wants to repeat the process or not. Once the user typed in her/his decision of NOT REPEATING THE PROCESS, the stored values in the array should be displayed all together For displaying the result array, you should use dereferencing the pointer approach. 6) 7) 8)
Use C programming,

Also please use “printf” function when displaying text
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C Program:

#include <stdio.h>

  

long fact(int n) {

   int c;

   long result = 1;

   for (c = 1; c <= n; c++)

      result = result*c;

   return result;

}

  

long C(int n, int r) {

   long result;    

   result = fact(n)/(fact(r)*fact(n-r));

   return result;

}

  

long P(int n, int r) {

   long result;

   result = fact(n)/fact(n-r);

   return result;

}

  

  

int main(){

   int n[100], r[100], j, i=0;

   long ncr[100], npr[100];

   char ch;

   do{

    do{

        printf("Enter the value of n: ");

        scanf("%d",&n[i]);

        printf("Enter the value of r: ");

        scanf("%d",&r[i]);

        if(r[i]>n[i])

            printf("n and r should be r<=n try agian:\n");

    }while(r[i]>n[i]);

    ncr[i] = C(n[i], r[i]);

    npr[i] = P(n[i], r[i]);

    i++;

    printf("Do you want to continue (Y/N): ");

    scanf(" %c",&ch);

   }while(ch == 'y' || ch == 'Y');

   for(j=0; j<i; j++){

        printf("%dC%d = %ld\n", n[j], r[j], ncr[j]);

        printf("%dP%d = %ld\n", n[j], r[j], npr[j]);

   }

   return 0;

}

Output:

Enter the value of n: 2 Enter the value of r: 4 n and r should be r<-n try agian: Enter the value of n: 4 Enter the value of r: 2 Do you want to continue (Y/N) : y Enter the value of n: 4 Enter the value of r: 3 Do you want to cont inue (Y/N): n 4C2 6 4P2 12 4C3 = 4 4P3 = 24

Add a comment
Know the answer?
Add Answer to:
Use C programming, Also please use “printf” function when displaying text In Probability, number of"combinations" (sometimes...
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
  • 1. In Probability, number of "combinations" (sometimes referred to as binomial coefficients) of'n times taken r...

    1. In Probability, number of "combinations" (sometimes referred to as binomial coefficients) of'n times taken r at a time is written as ritten as C(n,r)=(?)-_n! (n.) = !n . If an order conscious subset of r times taken from a set of n times - the permutations, it is written as n! P(n,r)= (n-1). Both cases, rsn. Create a script that will prompt the user to type in values for n and then calculate Conn and P(n,r). After the display...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

  • *Please try to use C++ specific coding for my understanding because I never learned C. A...

    *Please try to use C++ specific coding for my understanding because I never learned C. A polynomial P is a function defined by an array of coefficients CI. Example : C-(4, 2, 1), then In the general case, given the array CI of size N, we can define Write a program - with the function main0 that gets N, the coefficients C] and a value x from the user. - with a function poly( that calculates and returns the value...

  • Please create a program answering the following question in C PROGRAMMING. CorrectFormation Create a program and...

    Please create a program answering the following question in C PROGRAMMING. CorrectFormation Create a program and locally declare in main fname and Iname and completeName. Ask the user for their first and last name. Put the values into fname and Iname. You will create a function that is called as followed oinNames( fname, Iname, completeName ); You will pass the first name array, the last name array, and the array that will contain the complete name. The function named joinNames...

  • PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end...

    PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end please include a main function that tests the functions that will go into a separate driver file. Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...

  • daily21. Computing 1. C programming Please provide comments and write pre-condition and post-condition for the function....

    daily21. Computing 1. C programming Please provide comments and write pre-condition and post-condition for the function. Description Create a project called Daily21. Add a source file called daily21.c into the project. In this exercise, you will practice working with an array of integers. In the main function, you first need to create an integer array with 10 elements in t. Use a loop to read 10 integers from the user and store the values to the array (in the order...

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

  • C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible;...

    C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible; (2) use unique value array; (3) use flag array (flags used to avoid counting a number more than 1 time); (4) compute frequency distribution (use unique and count arrays); (5) use count array to store the frequency of a number. No global variable are permitted in this assignment. Do not change the code provided only write the missing code. Write the missing C++ statements...

  • Need helps on C++ attach. Thanks Pointers with classes a) A user-defined class named Timer has...

    Need helps on C++ attach. Thanks Pointers with classes a) A user-defined class named Timer has a constructor that takes two integer parameters to initialize hour and minute data members. Write a single C++ statement to create an object of the Timer class using dynamic memory allocation and assign it to a pointer variable named timePt r. It should call the constructor with two parameters. Use values of 10 and 20 for hour and minute respectively. b) Write the definition...

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