# October 14, 2008 Combination and Permutation

Permutation And Combination using C
*Permutation an Combination
this program to found permutation and combination of number
using C, we contruct using DevC++, you can use visual C, turbo C and many other
but maybe some funtion is not working
we recomended using DevC++ v 4.9
*/
#include “stdio.h”
#include “conio.h”
#include “stdlib.h”
#include “string.h”
#define MAX 20
/*it is function to calculate the permutation and combination using factorial*/
int factorial(int q)
{
if (q==0)
return(1);
else
return(q*factorial(q-1));/*this recursive funtions*/
}
/*this function to calculate the permutation*/
void permutation()
{
system(“cls”);/*clear konsole */
printf(“\tPermutation and Combination\n”);
printf(“\t===========================\n\n”);
char string[MAX];/*declare of array*/
printf(“input : “);
gets(string);/*take the string for string*/
int long_of_string = strlen(string);/*to get the long of the string, it use for looping*/
int flag=0;/*it for flag and index the ‘p’ position in the array*/
for(int i=0;i {
if(string[i]==’p’ || string[i]==’P’)/*try to find identifier p*/
{
flag=i;break;/*save the index of p in the array to flag*/
}
}
if(flag!=0)/*if the char p was found*/
{
int firts_number=atoi(string);/*convert the first number until char p*/
int second_number= atoi(&string[flag+1]);/*convert the second number begin from
char p*/
if(firts_number>=second_number)
{
int factorial_first_number=factorial(firts_number);/*calculate factorial of
first_number*/
int factorial_second_number=factorial(second_number);/*calculate factorial of
second_number*/
printf(“output : %d\n\n”,factorial_first_number/factorial_second_number);/*display
permutation of firts and second number*/
}
else {printf(“output : Imposible\n\n”);}/*if the first number less than the second
number that imposible to permutation*/
}
else{printf(“\nWrong\n”);}/*if the comand without p indentity, it display wrong
messege*/
}
/*this functions to calculate the combination*/
void combination()
{
system(“cls”);
printf(“\tpermutation and combination\n”);
printf(“\t===========================\n\n”);
char string[MAX];
printf(“input : “);
gets(string);
int long_of_string = strlen(string);/*calculate the long of string*/
int flag=0;/*it variabel to take index of char ‘c’ in the array*/
for(int i=0;long_of_string>i;i++)/*looping for found ‘c’*/
{
if(string[i]==’c’ || string[i]==’C’)/*if found char c*/
{
flag=i;break;
}
}
if(flag!=0)
{
int firts_number=atoi(string);/*convert the first number until char p*/
int second_number= atoi(&string[flag+1]);/*convert the second number begin from
char p*/
if(firts_number>second_number)
{
int factorial_of_third_number=factorial(firts_number-second_number);
int factorial_of_firts_number=factorial(firts_number);
int factorial_of_second_number=factorial(second_number);
printf(“output : %d\n\n”, factorial_of_firts_number/(factorial_of_third_number*
factorial_of_second_number));
}
else {printf(“output : imposible\n\n”);}/*if the first number less than the second
number that imposible to permutation*/
}
else{printf(“\nwrong code\n”);}/*if the comand without p indentity, it display wrong
messege*/
}
/*this is the main program*/
main(void)
{ char u;
do
{
system(“cls”);
printf(“\tpermutation and combination\n”);
printf(“\t===========================\n\n”);
printf(“1.PERMUTATION (ex : 12p5)\n2.COMBINATION (ex : 5c2 )\n\n”);
char p;
p=getch();/*try to take the choose of user*/
switch(p)
{
case ‘1’ : permutation();break;/*go to permutation function*/
case ‘2’ : combination();break;/*go to combination function*/
default : printf(“\nWRONG\n”);break;
}
printf(“PRESS Y FOR REPEAT : “);
u=getch();/*stop until user press any key*/
}while(u==’y’||u==’Y’);
}
{"ft_lang_label":"__label__en","ft_lang_prob":0.5256275,"math_prob":0.9814328,"size":3762,"snap":"2020-45-2020-50","text_gpt3_token_len":1027,"char_repetition_ratio":0.19771154,"word_repetition_ratio":0.15492958,"special_character_ratio":0.30515683,"punctuation_ratio":0.14012739,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99754345,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-12-04T11:46:31Z\",\"WARC-Record-ID\":\"<urn:uuid:c687463e-2076-4209-9985-19c76ffca221>\",\"Content-Length\":\"50596\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bed807fe-c730-4702-bd65-98c87eeddaf9>\",\"WARC-Concurrent-To\":\"<urn:uuid:834f55ac-c4ff-4118-98cd-8c3320848fbc>\",\"WARC-IP-Address\":\"103.8.79.89\",\"WARC-Target-URI\":\"http://www.goblooge.com/blog/combination-and-permutation/\",\"WARC-Payload-Digest\":\"sha1:NDL7C5XMSVTQBKLARDMSHC3EZHYPMZBJ\",\"WARC-Block-Digest\":\"sha1:L52CI4EK6ECZQO4PUHHIQSSOSWWSPOCJ\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141735600.89_warc_CC-MAIN-20201204101314-20201204131314-00518.warc.gz\"}"}