当前位置:网站首页>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
}
边栏推荐
- Unity常用的一些简易扩展方法
- MQTT协议------上
- Web服务(04)——LAMP的简介与搭建+DISCUZ论坛
- 十一、echo
- Navicat operation database
- Longest substring without duplicate characters
- Jenkins -- Basic -- 5.1 -- system configuration -- plug-in management
- [ctf attack and defense world] questions about cookies in the web area
- 【Oracle】获取最近工作日及前N个工作日
- C语言之数据存储汇总
猜你喜欢

13、 Command gadget

Network foundation of software test interview questions

十三、命令小工具

MySQL closes the problem of automatic submission of connection transactions

Jenkins -- Basic -- 03 -- post installation setup wizard

ESP8266 STA_ Server
![[question] what if Yum resources are occupied](/img/8d/50129fa1b1ef0aa0e968e6e6f20969.png)
[question] what if Yum resources are occupied

ESP8266 STA_UDP_Client

Mqtt---- bottom (precautions)

Unity UGUI Text文本框自适应
随机推荐
最大公约数的求法
The difference between if and else if
Question making notes 1
1. Mode
#MarkDown语法学习总结
Esp8266 connects to the IOT of Lexin cloud platform_ Demo
ESP8266接入云平台------DNS 域名连接服务器
Producer consumer model of concurrent programming
ESP8266-----SNTP获取网络时间
ESP8266 AP_ TCP_ Server
Some simple extension methods commonly used by unity
12、 Regular expression
Unity twitter login access
ESP8266 STA_TCP_Client
十一、echo
ESP8266 STA_ Mode
Download pronunciation pairs+ship or sheet+tree or three
Code merging of centralized version control tools
Basic DOS commands
ESP8266 AP_UDP_Server