当前位置:网站首页>[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
边栏推荐
- WebRTC实现简单音视频通话功能
- 读懂 互联网巨头 【中台之战】 以及 中台 发展思维
- C语言:浅谈各种复杂的声明
- [material delivery UAV] record (ROS + Px4 + yolov5 + esp8266 + steering gear)
- 恒星科通邀您“湘”约第24届中国高速公路信息化大会暨技术产品展示会
- Won't you just stick to 69 days? Merge range
- Cad2020 introductory learning (2021.4.13)
- Use of construction methods
- C语言力扣第61题之旋转链表。双端队列与构造循环链表
- Machine vision Series 2: vs DLL debugging
猜你喜欢

Visio draw grid

使用容器部署Jenkins

LeetCode_ Stack topics

MySQL - clustered index and secondary index

JVM (heap and stack) memory allocation

Two forms of softmax cross entropy + numpy implementation

Sequence list and linked list

Post export data, return

Machine vision Series 1: Visual Studio 2019 dynamic link library DLL establishment

Not for 61 days. The shortest word code
随机推荐
Coding questions encountered in the interview
Two forms of softmax cross entropy + numpy implementation
settings.xml
String, array, generalized table (detailed)
Why is it necessary to scale the attention before softmax (why divide by the square root of d_k)
Dabao and Erbao
10.回退消息
Class starts! See how smardaten decomposes complex business scenarios
It won't last for 70 days. The k-largest number in the array
Kotlin's list, map, set and other collection classes do not specify types
Semantic segmentation correlation
Visio draw grid
[k210 stepping pit] pytorch model is converted to kmodel and used on dock. (ultimately not achieved)
Definition and implementation of stack and queue (detailed)
[hands on deep learning] environment configuration (detailed records, starting from the installation of VMware virtual machine)
不会就坚持59天吧 替换单词
15.federation
Shell string segmentation
9. Delay queue
C语言:typedef知识点总结