[問題]數值無法放入陣列
開發平台(Platform): (Ex: Win10, Linux, ...)
OS
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
Xcode
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
為什麼輸入n,m無法讀入陣列
餵入的資料(Input):
18 6
預期的正確結果(Expected Output):
18 things is taken 6 at a time is 18564 exactly
錯誤結果(Wrong Output):
18564 things is taken 18564 at a time is 18564 exactly
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
//
// main.cpp
// sam
//
// Created by sam on 2019/9/3.
// Copyright ꤠ2019 sam. All rights reserved.
//
#include<iostream>
#include <stdio.h>
using namespace std;
long int lev(long int num){
long int a=1;
for(int i=1;i<=num;i++){
a=a*i;
}
return a;
}
int main(){
int i=0,count=0;
int n,m,k[i],l[i];
long int s[i];
long int num=1;
while(cin>>n>>m){
if(n==0||m==0){
break;
}
k[i]=n;
l[i]=m;
if(m<(n/2)){
m=n-m;
}
for(long int i=n;i>m;i--){
num=num*i;
}
m=n-m;
long int c=num/(lev(m));
s[i]=c;
i++;
count++;
}
for(int i=0;i<count;i++){
printf("%d things taken %d at a time is %ld exactly.\n",l[i],l[i],s[i]);
}
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.237.61.190 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1574425290.A.84F.html
→
11/22 20:34,
4年前
, 1F
11/22 20:34, 1F
→
11/22 20:34,
4年前
, 2F
11/22 20:34, 2F
→
11/23 00:45,
4年前
, 3F
11/23 00:45, 3F
→
11/23 01:42,
4年前
, 4F
11/23 01:42, 4F
推
11/23 02:23,
4年前
, 5F
11/23 02:23, 5F
→
11/23 02:23,
4年前
, 6F
11/23 02:23, 6F
→
11/23 02:24,
4年前
, 7F
11/23 02:24, 7F
→
11/23 08:53,
4年前
, 8F
11/23 08:53, 8F
→
11/23 08:54,
4年前
, 9F
11/23 08:54, 9F
→
11/23 08:58,
4年前
, 10F
11/23 08:58, 10F
→
11/23 13:59,
4年前
, 11F
11/23 13:59, 11F