当前位置:网站首页>1100: finding the number of combinations (function topic)
1100: finding the number of combinations (function topic)
2022-07-27 01:35:00 【Rookies also have dreams of entering big factories】
Title Description
There will be a new programming competition soon , What's different is that , This competition is based on class , In order to comprehensively measure the overall level of a class , Ask from a class m Choose from students k Students represent our class in the competition , Ask how many combinations there are . obviously , This combination number is m!/(k!(m-k)!). Ask to write a function fact(), Realize the factorial function of finding a number , This function is called in the main function .
long fact(long n)
{
// The return value of the function is n The factorial .
}
Input
Enter two positive integers m,k,k<=m<=12.
Output
Output an integer , That is, the number of combination schemes .
The sample input Copy
5 3
Sample output Copy
10
The code and detailed analysis are shown below :
#include <stdio.h>
#include <stdlib.h>
long fact(long n);
int main()
{
long m,k;
scanf("%ld %ld",&m,&k);
long mm,kk,pp; //mm by m The factorial ,kk by k The factorial ,pp by (m-k) The factorial
mm= fact(m);
kk= fact(k);
pp= fact(m-k);
long fa=mm/(kk*(pp));
printf ("%ld",fa);
return 0;
}
long fact(long n)
{
long s=1; //s The factorial value used to store the passed in value
for (;n>0;n--)
{
s=s*n;
}
return s;
// The return value of the function is n The factorial
}
边栏推荐
猜你喜欢
随机推荐
Mqtt protocol ----- above
ESP8266 STA_TCP_Server
c语言实现三子棋游戏
Introduction to various development software of advanced language
十六、awk
Complexity OJ question
iptables防火墙(二)
最大公约数的求法
Jenkins -- Basic -- 5.1 -- system configuration -- plug-in management
Basic DOS commands
链表常规OJ
Lamp+discuz Forum
软件测试面试题之软件基础
16、 Awk
Web服务器(01)——介绍web服务器
Remember that the scene rendered by rawimage is disordered once
ESP8266 AP_ UDP_ Server
[by pass] bypass method of WAF
Shortcut key introduction
ESP8266 AP_UDP_Server









