Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

nPr & nCr Calculator using C-Language




In this C program we will calculate the nPr or nCr and print the result, in the screen. The choice will be taken from the user. User can calculate nCr or nPr by choice.color>
If you are new in nPr or nCr and want to know about nPr or nCr,please, click below :
https://gradestack.com/Complete-CAT-Prep/Permutation-and/Meaning-and-Derivation-of/19142-3882-35788-study-wtw

input:

User's Choice. (i.e. 1.for nPr and 2.for nCr) & then, objects(n) and samples(r).

output:

The Calculated result will be printed on the screen.

CODE---->


#include
#include
#include
#include
color> int npr();
int ncr();
int fact(int num3);
main(){
     int choice;
     printf("*********Menu*********\ncolor>");
     printf("1.nPr\n2.nCr\n\ncolor>");
     printf("Please, Enter Your Choice : color>");
     scanf("%dcolor>",&choice);
     if(choice==1color>)
     npr();
     if(choice==2color>)
     ncr();
     getch();
}
     int npr()
     {
         int num1,num2,i,nr,answer_1,answer_2,answer_3;
         printf("\nP(n,r) \ncolor>");
         printf("Enter n(objects) :color>" );
         scanf("%dcolor>",&num1);
         printf("\nEnter r(sample) : color>");
         scanf("%dcolor>",&num2);
         answer_1=fact(num1);
         nr=num1-num2;
         answer_2=fact(nr);
         answer_3=answer_1/answer_2;
         printf("\n P(n,r) : %dcolor>",answer_3);
     }
     int ncr()
     {
   int num1,num2,i,nr,answer_1,answer_2,answer_3,answer_4,answer_5;
         printf("\nC(n,r) \ncolor>");
         printf("Enter n(objects) :color>" );
         scanf("%dcolor>",&num1);
         printf("\nEnter r(sample) : color>");
         scanf("%dcolor>",&num2);
         answer_1=fact(num1);
         nr=num1-num2;
         answer_2=fact(nr);
         answer_3=fact(num2);
         answer_4=answer_2*answer_3;
         answer_5=answer_1/answer_4;
         printf("\n C(n,r) : %dcolor>",answer_5);
     }
     int fact(int num3)
     {
         int i,ans=1;
         for(i=1color>;i;i++color>)
         {
             ans=ans*i;
         }
         return ans;
         }





Don't just read, write it, run it.....color>

RESULT:color>





This post first appeared on ProgramJoy.blogspot.com, please read the originial post: here

Share the post

nPr & nCr Calculator using C-Language

×

Subscribe to Programjoy.blogspot.com

Get updates delivered right to your inbox!

Thank you for your subscription

×