您的回答能详细完整点么,感觉跟我想要的答案很接近 谢谢
追答非要我把整个程序写完啊,中心代码已经完成了
只要加上头尾,输入输出就好了
main()
{
int i,n,b=1,s=1;
float sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
b*=i; //这个b是阶乘
sum+=1.0/b*s;
s*=-1; //这个是正负号
}
printf("%f\n",sum);
}
C语言:求1-1\/2!+1\/3!-1\/4!+……+1\/n!的值
printf("请输入(1-1\/2!+1\/3!-1\/4!+……+1\/n!)的n:");scanf("%d",&n);fflush(stdin);if ( n>0 ) break;else printf("\\nERROR:错误,输入有误,重新输入!\\n");} for(i=1;i<=n;i++){ printf("[%d]%f,%f\\n",i,sum,1.00\/js(i));if (i%2==0) sum=sum-1.00...
用C语言求s=1-1\/2!+1\/3!-1\/4!+……+1\/n!其中n的值由键盘输入(急!!)
include <stdio.h> double factorial(int n){ double f = 1 ;for (int t=1 ; t<= n ; t++){ f = f*t ;} return f;} void main(){ int n, k=1;double s = 0 ;printf("Input n\\nn=") ;scanf("%d", &n) ;for (int t=1; t<=n; t++){ s = s + ((double...
C语言程序 1-1\/2+1\/3-1\/4+...+1\/99-1\/100
1-1\/2+1\/3-1\/4+...+1\/n 才需要输入n 代码如下(不需要math.h头文件):include <stdio.h>void main(){ double sum; int i,n,m; \/\/加个变量i printf("请输入n:"); scanf("%d",&n); for(i=1,m=1,sum=0;i<=n;i++) \/\/n改为i,100改为n { ...
用c语言编写函数求表达式1-1\/2+1\/3-1\/4+1\/5-1\/6+1\/7-…+1\/n的值?
printf("请输入n的值\\n");scanf("%d",&n);for(i=1;i<=n;i++){ x=x+1.0\/i*f;f=-f;} printf("数列的值为:%f",x);}
用c语言编写函数求表达式1-1\/2+1\/3-1\/4+1\/5-1\/6+1\/7-…+1\/n的值
include <stdio.h> main(){ int n,sign=1,i;double sum=0.0;printf("Enter n:");scanf("%d",&n);for(i=1;i<=n;i++){ sum+=sign*1.0\/i;sign=-sign;} printf("sum=%lf\\n",sum);}
用C语言编程:求1-1\/2+1\/3-1\/4+1\/5-1\/6+…+1\/99-1\/100+…的值…
double sum,k=1;\/\/定义求和变量和转变符号的变量的初值 printf("please input number n:\\n");\/\/提示用户输入想要的分母值 scanf("%d",&n);\/\/需要用户输入的n的值 for(i=1,sum=0;i<=n;i++)\/\/循环从1到n进行求和 { sum+=k\/i;\/\/累加求和 k*=-1;\/\/实现符号的变换 } printf("%...
1-1\/2+1\/3+…+1\/n用函数c语言
include"stdio.h"int main(){int i,n;float s=0;scanf("%d",&n);for(i=1;i<=n;i++)if(i%2)s+=1.0\/i;else s-=1.0\/i;printf("%f\\n",s);system("pause");return 0;}
C语言求1-1\/2!+1\/3!-1\/4!...(-1)^(n-1)*1\/n!,最后一个精度为...
int i = 0,num=1,sign = 1;double sum=0.0;for(i=1;;i++){ if((1.0\/num)<0.00000001)break;else sum+=(1.0\/(num*=i))*sign;sign = -sign;}
c语言1-1\/2+1\/3-1\/4+1\/5……+(-1)的n-1次方1\/n.在源程序中输入n的值
include <stdio.h>#include <conio.h>int main (void) {double sum;int sign = 1; \/* 控制正负符号 *\/int n;int i;scanf ("%d", &n);sum = 0;for (i=1; i<=n; i++) {sum += 1.0*sign\/i;sign *= -1;}printf ("1 - 1\/2 + 1\/3 - 1\/4 + 1\/5 ... 1\/%d ...
C语言数列的求和1-1\/2+1\/3-1\/4...的编写
1、a=pow(-1,y),对于给定的n,则a的正负是一定的,起不到改变正负号的作用。2、for循环需要用大括号括起来。3、其它不再赘述,下面是具体修改的方法。修改:include<stdio.h>#include<math.h> \/\/没有必要加载int main(){double n,i,sum,y,a=1; \/\/对a赋初值1,不需要变量ywhile(scan...