❶ 編程求級數的程序怎麼寫c語言

#include <stdio.h>
#include <math.h>

int main(void)
{
double f = 1;
double x, k, x2, power = 1;
int i = 2;
scanf("%lf", &x);
power += x;
k = x;

do {
x2 = power;
f *= i++;
x *= k;
power += x / f;
} while(fabs(power-x2) > 1e-8);
printf("%f", power);
}

/////////////////////////

你那個代碼,1、pow函數可以不用自己寫,你寫的精度也不夠;2、保存階乘最好用double,不然要溢出。
修正了以上2點就沒問題了,代碼如下:

#include <stdio.h>
#include <math.h>

double f1(int n)
{
double s = 1;
int i;
for ( i=1; i<=n; i++)
s *= i;
return s;
}

main()

{
int x,i, n;

double ex = 1;
scanf("%d%d",&x,&n);
for ( i=1; i<=n; i++)

ex += pow(x, i) / f1(i);

printf("%lf %lf\n",ex, exp(x));
}

❷ C語言求級數

#include <stdio.h>
double fun(double x,int n)
{
double result = 1.0;
double item = 1.0;
int i;

for (i = 1; i <= n; i++)
{
item = item * x / i;
result += item;
}

return result;
}
int main()
{
double x;
int n;
scanf("%lf%d",&x,&n);
printf("%lf\n",fun(x,n));
}

❸ C語言級數求和

#include"stdio.h"/////////不知道是否正確,希望有幫助.
double x;
double jiecheng(double a){//介乘。
double i=0;
double r=1;
for(i=1;i<(a+1);i++)
r=i*r;
return r;
}
double pf(double a){
static p=0;
double r;
p++;
r=x*a/(jiecheng(a));
if(p%2==0)
return r*-1;
else
return r;
}
void main()
{
int i=1;
double r=0;
scanf("%lf",&x);
for(i=1;i<1000;i+=2)
r=r+pf(i);
printf("%.6lf\n",r);

}

❹ C語言求級數的問題

#include<stdio.h>
#include<math.h>
voidmain(){
inti;doublex,k=1,s=0;
scanf("%lf",&x);
for(i=0;abs(k/(i*2+1))>=1e-6;i++)
{
i==0?k*=x:k*=-x*x/i;
s+=k/(i*2+1);
}
printf("s(x)=%lf",s);
}

❺ C語言計算無窮級數

^

#include<stdio.h>
#include<math.h>
/*
數列求和來題。輸入x,計算無窮級數。源
1+x-x^2/2!+x^3/3!-x^4/4!...
所有絕對值不小於0.0001。
要求最終結果保留四位小數。
*/

intmain()
{
doublesum=1;
doublex;
doubletemp=1;
doublei;

printf("PleaseTypeX! ");
scanf("%lf",&x);


for(i=1;fabs(temp)>=0.0001;i++)
{
temp=x*temp/i;
sum+=temp;
temp=-temp;
}

printf("%.4lf ",sum);
return0;

}

❻ c語言級數求和題

/*一個計算n個數的平均值的函數*/
float ave(float *num,int n)
{
float cache=0.0;

int i=0;
for(;i<n;i++)

{
cache=cache+num[i];//求數的總和

}

return(cache/n);//返回專平屬均值

}

❼ C語言:求下列級數的和,怎麼編程

代碼文本:

#include "stdio.h"

int main(int argc,char *argv[]){

double s,x,t;

printf("Enter x(R: x>1)... x=");

if(scanf("%lf",&x)==1 && x>1.0){

for(t=s=1.0;(t/=x)>1.0E-6;s+=t);

printf("s(%f) = %f ",x,s);

}

else

printf("Input error, exit... ");

return 0;

}

❽ C語言中求級數和

你前面來寫的那個式子就有問題自,怎麼又7+8+9了?
從程序來看,最裡面的循環是求每一個加數,例如N為5,那麼就有5個加數,分5次循環求得這5個加數。由於第一個加數是1,所以循環中沒有求第一個加數,而是直接從第二個加數開始求,這也就是你所問的t=1時,f=2,由於j從0循環到i(包含),也就是,也就是i+1個數相乘,例如i=1時,所求加數就是2*3
j就是一個循環控制變數,控制乘數的大小

外面一層循環就是將加數求和

❾ C語言 計算級數1/2+1/2*3....... +1/n(n+1)

#include <stdio.h>
void main()
{
int i,n;
float sum = 0; //sum賦初值0
printf(" please input a number n:");
scanf("%d",&n);
for (i = 1; i <= n; i++)
sum = 1.0/(i*(i+1))+sum; //利用for循環求sum,因為sum浮點型,所以分子用1.0
printf("sum=%.4f\n",sum); //輸出sum,保留四位小數
}