当前位置:网站首页>[c language] PTA 7-48 find the number of combinations
[c language] PTA 7-48 find the number of combinations
2022-07-29 04:29:00 【LastWhisperw】
This question requires the preparation of procedures , According to the formula Cnm=n!/(n−m)!m! Calculate from n Take out... Of the different elements m Elements (m≤n) The combination number of .
It is recommended to define and call functions fact(n)
Calculation n!
, among n
The type is int
, The function type is double
.
Input format :
Enter two positive integers on one line m and n(m≤n), Space off .
Output format :
By format “result = Calculation result of combination number ” Output . The results are as follows double
Within the scope of type .
sample input :
2 7
No blank lines at the end
sample output :
result = 21
No blank lines at the end
Listen to the questions , Order one double fact(int n)
#include<stdio.h>
double fact(int n);
int main(){
int n,m;
scanf("%d %d",&m,&n);
double ans;
ans=fact(n)/(fact(m)*fact(n-m));
printf("result = %.0f",ans);
return 0;
}
double fact(int n){
int i;
double f=1.0;
for(i=2;i<=n;i++){
f*=i;
}
return f;
}
Be careful :
①fact Return value f, Number of combinations output ans Must be double type , Otherwise, the answer will be wrong ( Why? ...
② Convert a double value to int Data loss occurs when type
边栏推荐
- Kotlin's list, map, set and other collection classes do not specify types
- 不会就坚持63天吧 最大的异或
- Interview notes of a company
- 用 ZEGO Avatar 做一个虚拟人|虚拟主播直播解决方案
- Semantic segmentation correlation
- settings.xml
- Make a virtual human with zego avatar | virtual anchor live broadcast solution
- kotlin的List,Map,Set等集合类不指定类型
- HC06 HC05 BT
- Flutter实战-请求封装(二)之dio
猜你喜欢
TypeError: Cannot read properties of undefined (reading ‘then‘)
Won't you just stick to 69 days? Merge range
Record of problems encountered in ROS learning
顺序表和链表
Jenkins 参数化构建中 各参数介绍与示例
Make a virtual human with zego avatar | virtual anchor live broadcast solution
11. Backup switch
Visio draw grid
不会就坚持69天吧 合并区间
Installation and use of stm32cubemx (5.3.0)
随机推荐
Dabao and Erbao
Machine vision Series 1: Visual Studio 2019 dynamic link library DLL establishment
10.回退消息
Exception resolution: error of not finding edu.stanford.nlp.semgraph.semgrex.semgrexpattern in cococaption package
Niuke IOI weekly 27 popularity group
顺序表和链表
Basic operation of queue
DASCTF2022.07赋能赛
9.延迟队列
15.federation
[common commands]
Kotlin's list, map, set and other collection classes do not specify types
Two forms of softmax cross entropy + numpy implementation
不会就坚持65天吧 只出现一次的数字
不会就坚持66天吧 权重生成随机数
Dasctf2022.07 empowerment competition
6. Pytest generates an allure Report
你真的会写Restful API吗?
不会就坚持67天吧 平方根
15.federation