[問題]printf 輸出問題
開發平台(Platform): (Ex: Win10, Linux, ...)
Os
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
Xcode
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
為什麼輸出是0
餵入的資料(Input):
18
6
預期的正確結果(Expected Output):
18564
錯誤結果(Wrong Output):
c輸出0
程式碼(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(int num){
long int a=1;
for(int i=1;i<=num;i++){
a=a*i;
}
return a;
}
int main(){
int n,m;
long int num=1;
cin>>n>>m;
if(m<(n/2))
m=n-m;
while(n>m){
num=num*n;
n--;
}
cout<<num<<"\n";
long int c=num/lev(m);
printf("%lu",c);
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 110.28.229.101 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1574083743.A.DD4.html
※ 編輯: samsandy (110.28.229.101 臺灣), 11/18/2019 21:29:38
→
11/18 21:41,
4年前
, 1F
11/18 21:41, 1F
→
11/18 21:47,
4年前
, 2F
11/18 21:47, 2F
→
11/18 21:48,
4年前
, 3F
11/18 21:48, 3F
→
11/18 21:50,
4年前
, 4F
11/18 21:50, 4F
→
11/18 21:55,
4年前
, 5F
11/18 21:55, 5F
→
11/18 21:57,
4年前
, 6F
11/18 21:57, 6F
→
11/18 22:08,
4年前
, 7F
11/18 22:08, 7F
推
11/19 09:26,
4年前
, 8F
11/19 09:26, 8F
→
11/19 09:26,
4年前
, 9F
11/19 09:26, 9F
→
11/19 09:29,
4年前
, 10F
11/19 09:29, 10F
→
11/19 09:29,
4年前
, 11F
11/19 09:29, 11F