找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1658|回復: 1
打印 上一主題 下一主題
收起左側

計算排列和組合源代碼[修改bug&簡化]

[復制鏈接]
跳轉到指定樓層
樓主
ID:107189 發(fā)表于 2016-3-5 15:45 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include <stdio.h>-
void print_date (int a,int b) {-
   printf("n = %d , m = %d",a,b);-
}-
-
int pailie (int a,int b) {-
    int tmp = 1;-
    for (b--;0!=(b+1);b--) {-
         tmp*=(a-b);-
    }-
    return tmp;-
}-
-
-
int zuhe (int a,int b) {-
    int c,d=1,e=1;-
    c=b;-
    for (--c;(c+1)!=0;--c) {-
       d*=(a-c);-
    }-
    c=b;-
    for (--c;(c+1)!=0;--c) {-
       e*=(b-c);-
    }-
  return d/e;-
}-
-
int main (void) {-
   int x,y,i,tmp,choose;-
   printf("input 2 number\n");-
   printf("the one=");-
   scanf("%d",&x);-
   printf("the two=");-
   scanf("%d",&y);-
   if (y>x){-
     i=x;-
     x=y;-
     y=i;-
   }-
     do {-
       printf("\n m A n input 1 \t  m C n input 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;-
}-

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:107189 發(fā)表于 2016-3-5 15:45 | 只看該作者
#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("輸入兩個數(shù)字\n");
   printf("第一個數(shù)字=");
   scanf("%d",&x);
   printf("第二個數(shù)字=");
   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;
}
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表