1輸入正整數n用3種方法分別計算下式的和

2021-05-04 21:49:24 字數 5893 閱讀 7389

1樓:匿名使用者

這個是第一種:

#include

void main()

這個是第二種:

#include

int fact(int n)

void main()

第三種不太理解。。。不好意思。

2樓:大氣貓

/printf(", total).4f\ i

total += temp;= n;

double total = 0.h"

double total = 0:%:%;;= n;巢狀迴圈, temp = 1.0, total); j >.0; i <.0;

total = total + temp.0; i;;

/%d" j, &n); j--)

temp = temp / i++)

return total;

double fact(int n)

int main(void)

printf("

}printf("n"

return 0

/total);巢狀迴圈;呼叫函式; i++)total += temp /.0;一重迴圈&n).4f\= n.4f\ j--)

total = total + temp /}int main(void)

{int i;%d"

/= j;

printf("

return 0

j;= n;n"= 1

n; i++)

{temp = 1;n" i <.4f\.0; i++)total = total + temp /scanf("

for (i = 1;/

for (i = 1;

double total = 0.0;iostream>= i.0;

for (j = i;

temp = 1;

using namespace std;;

fact(n))

total); j >

/double total = 0; i < i <;

printf("呼叫函式

total = 0;n":%:%:%;一重迴圈for (i = 1;/.0;巢狀迴圈

total = 0;= n;

return total

3樓:匿名使用者

#include

using namespace std;

double fact(int n)

int main(void)

4樓:匿名使用者

#include "stdio.h"

double fact(int n)

return total;

}int main(void)

printf("一重迴圈:%.4f\n", total);

//呼叫函式

total = 0.0;

printf("呼叫函式:%.4f\n", fact(n));

//巢狀迴圈

total = 0.0;

for (i = 1; i <= n; i++)printf("巢狀迴圈:%.4f\n", total);

return 0;}

用c語言程式設計 :輸入一個正整數n 用3種方法分別計算下式的和 保留4位小數

5樓:匿名使用者

#include "stdio.h"

double fact(int n)

return total;

}int main(void)

printf("一重迴圈:%.4f\n", total);

//呼叫函式

total = 0.0;

printf("呼叫函式:%.4f\n", fact(n));

//巢狀迴圈

total = 0.0;

for (i = 1; i <= n; i++)printf("巢狀迴圈:%.4f\n", total);

return 0;}

6樓:大氣貓

/printf(", total).4f\ i

total += temp;= n;

double total = 0.h"

double total = 0:%:%;;= n;巢狀迴圈, temp = 1.0, total); j >.0; i <.0;

total = total + temp.0; i;;

/%d" j, &n); j--)

temp = temp / i++)

return total;

double fact(int n)

int main(void)

printf("

}printf("n"

return 0

/total);巢狀迴圈;呼叫函式; i++)total += temp /.0;一重迴圈&n).4f\= n.4f\ j--)

total = total + temp /}int main(void)

{int i;%d"

/= j;

printf("

return 0

j;= n;n"= 1

n; i++)

{temp = 1;n" i <.4f\.0; i++)total = total + temp /scanf("

for (i = 1;/

for (i = 1;

double total = 0.0;iostream>= i.0;

for (j = i;

temp = 1;

using namespace std;;

fact(n))

total); j >

/double total = 0; i < i <;

printf("呼叫函式

total = 0;n":%:%:%;一重迴圈for (i = 1;/.0;巢狀迴圈

total = 0;= n;

return total

7樓:匿名使用者

#include

using namespace std;

double fact(int n)

int main(void)

讀入1個正實數x和1個正整數n(n<=50)計算x的n次冪保留兩位小數

8樓:兄弟連教育北京總校

#include

float x;

int n,i;

float s=1.0;

void main()

{printf("please input x:");

scanf("%f",&x);

printf("please input num:");

scanf("%d",&n);

if(n

輸入一個正整數n,計算1-1/4+1/7-1/10+1/13-1/16+...前n項之和.(保留兩位小數)

9樓:墨汁諾

用一個for單迴圈就可以解決。

#include

#include

void main()

printf("%.2f",x);

system("pause");}

10樓:匿名使用者

#include

#include

int main()

if(i>=n+1) printf_s("\n所求前n項和s=%5.2f\n\n",s);

return 0;

}執行示例:

11樓:真de無上

sum[(-1)^(n + 1)/(3 n - 2), ]

y看你要到幾了

12樓:聽不清啊

用一個for單迴圈就可以解決了。

13樓:匿名使用者

#include

#include

using namespace std;

double sum(int a)

cout<}

int main()

14樓:匿名使用者

#include

#include

void main()

printf("%.2f",x);

system("pause");}

15樓:匿名使用者

n employee at the shenzhe

16樓:此人正在輸入

ral integrity of the trains to

c語言,求e的值:輸入1個正整數n,計算下式的前n項之和(保留4位小數)。要求使用巢狀迴圈。

17樓:

static double cale(int n)

return res;

}也可以不用巢狀迴圈。。

18樓:匿名使用者

#include

int main()

e += 1/f;

}printf("e=%f\n", e);

return 0;

}如果滿足你的需求,請採納...

19樓:匿名使用者

for裡邊帶for就行啊

20樓:匿名使用者

unsigned long factorial(unsigned long n)

//n!

unsigned double func(unsigned long n)

printf("%.4lf", func(n));

c語言級數求和題

21樓:頂頂頂頂分

#include "stdio.h"

int main()

表示bai

哪一項du,zhisum表示此dao

時各項專之和屬}

22樓:匿名使用者

#include "stdafx.h"

#include "stdio.h"

int main(int argc, char* argv)//printf("e= %4f",ret);

printf("e= %0.4f",ret);

printf("done");

return 0;

#include "stdafx.h"

#include "stdio.h"

int main(int argc, char* argv)//printf("e= %4f",ret);

printf("e= %0.4f",ret);

printf("done");

return 0;

#include "stdafx.h"

#include "stdio.h"

int main(int argc, char* argv)while(i

//printf("e= %4f",ret);

printf("e= %0.4f",ret);

printf("done");

return 0;}

23樓:匿名使用者

#include

double fact(int n)

int main(void)

輸入正整數n,再輸入n個正整數,判斷它們是否為素數素

include int main void if i m 2 m 1 printf d is shushu n m else printf d is not shushu n m return 0 你好很高興為你copy解答 答案是 你的程式bai結構du錯了,for迴圈是用來判斷一個數是zhi否為...

輸入正整數a和n,求a aa aaa aa a(n個a

是 2 22 222 你的程式是 2 2 2 2 2 2 如果不考錄溢位的話 你可以 用 for int i 0 i 如果是這個3 33 333 369,你那就錯了,你那程式只是符合特別的 這個可以滿足你的要求 include include int main void sum a printf s...

c語言輸入正整數n將其逆序輸出例如輸入

c語言輸入一個正整數n,將其逆序輸出 include include int main printf n return 0 執行結果如下 就不給你寫了,提供演算法吧。首先判斷輸入的正整數的位數,例如1000 n 9999 然後輸出m 注意,c語言裡方括號是取整運算子號 因為是整型運算,其實方括號可以...