Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone please show me the appropriate code to produce the desired outcome f

ID: 3535726 • Letter: C

Question

Can someone please show me the appropriate code to produce the desired outcome for this assignment? I am in an online C programming class with no one to ask questions to. The book describes code but doesn't actually show how to write it. Any and all explanations, no matter how basic or trivial, will be greatly appreciated. Thanks!

Languages such as C typically provide a function to compute factorials, but in this assignment you need to do the computation in your own code (this requires looping). In other words, don't use the library functions to compute combinations or factorials - do it in your program.

The assignment is to create a program to display the number of combinations where n and k are entered by the user. Do not use the built-in C function to compute either combinations or factorials - do the arithmetic in your program!

Reject any input greater than 10 or less than 1 by displaying an error message and then asking the user to re-enter the input. Do this as many times that they enter incorrect input. This applies both to n and k.

Additionally for k, there is an extra condition that k <= n

Assume that all of the internal calculations can be done using integers, i.e. don't worry about integer overflow.

Output should be formatted as shown in the sample.

Explanation / Answer

#include<stdio.h>
int main()
{
int n,k;
long f(int);
clrscr();
printf("Enter the number of items in the list(n):");
scanf("%d",&n);
if(n>10||n<2)
printf("Invalid input:Number must be between 1 and 10 ");
else
printf("Enter number of items to choose(k):");
scanf("%d",&k);
if(k>n||k<2)
printf("Invalid input:Number must be between 1 and %d ",n);
else
printf("Number of combinations:%d",f(n)/(f(k)*f(n-k)));
getch();
return 0;

}
long int f(int x)
{
if(x==1)
return 1;
else
return x*f(x-1);
}