计算组合和排列的源代码
程序代码:
#include <stdio.h> void print_date (const int a,const int b) { printf("n = %d , m = %d",a,b); } int pailie (int a,int b) { int tmp = 1; for (b-=1;0!=(b+1);b--) { tmp*=(a-b); } return tmp; } int zuhe (int a,int b) { int tmp,c,d,e; c=b; for (c-=1;(c+1)!=0;c--) { d*=(a-c); } c=b; for (c-=1;(c+1)!=0;c--) { e*=(b-c); } tmp = d/e; return tmp; } int main (void) { int x,y,i,tmp,choose; printf("输入两个数字\n"); printf("第一个数字="); scanf("%d",&x); printf("第二个数字="); scanf("%d",&y); if (y>x){ i=x; x=y; y=i; } do { printf("\n计算m A n输入1,计算m C n输入2 :"); scanf("%d",&choose); } while (choose>2); print_date (x,y); switch (choose) { case 1: tmp = pailie (x,y); printf("\n n A m =%d\n",tmp); break; case 2: tmp = zuhe (x,y); printf("\n n C m =%d\n",tmp); break; } scanf("%d",&i); return 0; }