亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么 n 為20 階乘為負數

? ?#include<stdio.h>

? int prodict(int n){

? int ss;

? if(n < 0){

? printf("輸入錯誤!");

? return 0;

? }

? if(n == 1 || n == 0){

?return 1;

? }

?else {

?ss = prodict(n-1) * n;

?}

? return ss;

?}

?int main() {

?printf("n=%d: %d\n", 1, prodict(1));

?printf("n=%d: %d\n", 2, prodict(2));

?printf("n=%d: %d\n", 3, prodict(3));

?printf("n=%d: %d\n", 4, prodict(4));

?printf("n=%d: %d\n", 5, prodict(5));

?printf("n=%d: %d\n", 6, prodict(6));

?printf("n=%d: %d\n", 7, prodict(7));

?printf("n=%d: %d\n", 7, prodict(8));

?printf("n=%d: %d\n", 9, prodict(9));

?printf("n=%d: %d\n", 10, prodict(10));

?printf("n=%d: %d\n", 20, prodict(20));

?printf("n=%d: %d\n", 30, prodict(30));

?printf("n=%d: %d\n", 50, prodict(50));

?return 0;

?}


運算結果:

n=1: 1

n=2: 2

n=3: 6

n=4: 24

n=5: 120

n=6: 720

n=7: 5040

n=7: 40320

n=9: 362880

n=10: 3628800

n=20: -2102132736

n=30: 1409286144

n=50: 0



正在回答

1 回答

超界??紤]int型范圍在-32768~32767,用實型更妥當

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么 n 為20 階乘為負數

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號