当前位置:网站首页>[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 7No blank lines at the end
sample output :
result = 21No 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
边栏推荐
- Whether the modification of import and export values by ES6 and commonjs affects the original module
- Deploy Jenkins using containers
- Don't stick to it for 68 days. Baboons eat bananas
- Actual combat of flutter - DIO of request encapsulation (II)
- Use of construction methods
- Wechat applet parameter transfer
- settings.xml
- 不会就坚持68天吧 狒狒吃香蕉
- Basic operation of queue
- Pytoch automatic mixing accuracy (AMP) training
猜你喜欢

WebRTC实现简单音视频通话功能

HC06 HC05 BT

使用容器部署Jenkins

你真的会写Restful API吗?

Unity基础(3)—— unity中的各种坐标系
![Understand the Internet giant [the war between China and Taiwan] and the development thinking of China and Taiwan](/img/6c/f24407133663c0e19d6fa05c611341.png)
Understand the Internet giant [the war between China and Taiwan] and the development thinking of China and Taiwan

Not for 58 days. Implement prefix tree
![[hands on deep learning] environment configuration (detailed records, starting from the installation of VMware virtual machine)](/img/fe/8c707c30c734de7bb76ea68134842c.png)
[hands on deep learning] environment configuration (detailed records, starting from the installation of VMware virtual machine)

不会就坚持59天吧 替换单词

Class starts! See how smardaten decomposes complex business scenarios
随机推荐
通过js来实现一元二次方程的效果,输入a,b,c系数后可计算出x1和x2的值
oracle 更新和删除数据
Mongo Shell交互式命令窗口
Machine vision series 3:vs2019 opencv environment configuration
Wechat applet parameter transfer
Differences and principles of bio, NiO and AIO
String, array, generalized table (detailed)
Fuzzy query of SQL
Update learning materials daily
6.pytest生成allure报告
Coding questions encountered in the interview
C language: summary of consortium knowledge points
Visio draw grid
Multi card training in pytorch
C语言:枚举知识点总结
C语言:typedef知识点总结
Deep learning training strategy -- warming up the learning rate
Make a virtual human with zego avatar | virtual anchor live broadcast solution
11.备份交换机
MySQL - clustered index and secondary index