A C

本文介绍了一个简单的C语言程序,用于计算组合数学中的排列(A)和组合(C)问题。通过输入字符'A'或'C'及两个整数n和m,程序能够输出对应的排列或组合结果。
Problem Description
Are you excited when you see the title "AC" ? If the answer is YES , AC it ;

You must learn these two combination formulas in the school . If you have forgotten it , see the picture.




Now I will give you n and m , and your task is to calculate the answer .
 
Input
In the first line , there is a integer T indicates the number of test cases.
Then T cases follows in the T lines.
Each case contains a character 'A' or 'C', two integers represent n and m. (1<=n,m<=10)
 
Output
For each case , if the character is 'A' , calculate A(m,n),and if the character is 'C' , calculate C(m,n).
And print the answer in a single line.
 
Sample Input
2
A 10 10
C 4 2
 
Sample Output
3628800
6
 
 1 #include <stdio.h>
 2 
 3 int jieCheng(int number);
 4 
 5 int main(){
 6     int T;
 7     char c;
 8     int n;
 9     int m;
10     int n_jieCheng;
11     int m_jieCheng;
12     int n_m_jieCheng;
13     int result;
14     
15     scanf("%d",&T);
16     
17     while(T--){
18         getchar();
19         
20         scanf("%c%d%d",&c,&n,&m);
21         
22         n_jieCheng=jieCheng(n);
23         m_jieCheng=jieCheng(m);
24         n_m_jieCheng=jieCheng(n-m);
25         
26         if(c=='A')
27             result=n_jieCheng/n_m_jieCheng;
28         
29         else
30             result=n_jieCheng/(m_jieCheng*n_m_jieCheng);
31             
32         printf("%d\n",result);
33     }
34     return 0;
35 }
36 
37 int jieCheng(int number){
38     int result;
39     int i;
40     
41     result=1;
42     
43     for(i=1;i<=number;i++)
44         result*=i;
45         
46     return result;
47 }

 

 

转载于:https://www.cnblogs.com/zqxLonely/p/4085910.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值