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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

程序填空,不要改變與輸入輸出有關的語句,該怎么處理?

程序填空,不要改變與輸入輸出有關的語句,該怎么處理?

手掌心 2022-07-08 18:07:49
輸入一個正整數repeat (0<repeat<10),做repeat次下列運算:輸入一個整數n (n>=0)和一個雙精度浮點數x,輸出函數p(n,x)的值(保留2位小數)。[1 (n=0)p(n, x) = [x (n=1)[((2*n-1)*p(n-1,x)-(n-1)*p(n-2,x))/n (n>1)例:括號內是說明輸入3 (repeat=3)0 0.9 (n=0,x=0.9)1 -9.8 (n=1,x=-9.8)10 1.7 (n=10,x=1.7)輸出p(0, 0.90)=1.00p(1, -9.80)=-9.80p(10, 1.70)=3.05#include <stdio.h>double p(int n, double x);int main(void){int repeat, ri;int n;double x, result;scanf("%d", &repeat);for(ri = 1; ri <= repeat; ri++){scanf("%d%lf", &n, &x);result = p(n, x);printf("p(%d, %.2lf)=%.2lf\n", n, x, result);}}
查看完整描述

2 回答

?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

#include <stdio.h>
double p(int n, double x);

int main(void)
{
int repeat, ri;
int n;
double x, result;

scanf("%d", &repeat);
for(ri = 1; ri <= repeat; ri++)
{
scanf("%d%lf", &n, &x);
result = p(n, x);
printf("p(%d, %.2lf)=%.2lf\n", n, x, result);
}
}

double p(int n, double x)
{ double result;
if(n==0) result= 1;
else if(n==1) result=x;
else result=((2*n-1)*p(n-1,x)-(n-1)*p(n-2,x))/n;
return result;
}


查看完整回答
反對 回復 2022-07-11
?
九州編程

TA貢獻1785條經驗 獲得超4個贊

您這種寫法有很大問題,首先用戶的輸入n是不確定的,主程序是不能這么寫的,因為無法保存前面幾次輸入的數,后面的結果也沒法確定了,而對于n應該讓計算機自動處理,不能讓用戶輸入的。主程序是錯誤的,必須要改變。

查看完整回答
反對 回復 2022-07-11
  • 2 回答
  • 0 關注
  • 198 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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