当前位置:三九宝宝网 → 宝宝教育 → 教学论文 → 正文

C语言编程:计算S x 2x^23 4x^45 6x^67 x属于1

更新:03-17 整理:39baobao.com
字体:

[计算机二级c语言]总体上必须清楚的:1)程序结构是三种: 顺序结构 , 循环结构(三个循环结构), 选择结构(if 和 switch)2)读程序都要从main()入口, 然后从最上面顺序往下读(碰到循环做循环,碰到选择做选择)。3)...+阅读

展开全部

#include

#include

int main()

{

char sign = -1;

int n = 0, n_factorial = 1;

double x, xn, S;

do

{

printf("Please input x([1,2]): ");

scanf("%lf", &x);

}while(!(1 <= x & x <= 2));//限制输入范围必须[1,2]

S = -x;

do

{

sign = -sign;//计算符号

n++; //计算当前n,n=0,1,2,3,...

n_factorial = n_factorial *(2*n) * (2*n + 1); //计算阶乘(2n+1)!

xn = (2*n)*pow(x, 2*n)/n_factorial; //计算第n项值(不包括负号)2n*x^(2n)/(2n+1)!

S += sign * xn; // 计算S=S+符号*xn

}while(xn >= (1e-5));//第n项的值大于等于10^-5时,重复循环

printf("The result S is : %lf\n", S);

}

本文地址:https://www.39baobao.com/show/29_48718.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

C语言一个薪水计算问题#include<stdio.h> void main() { int h; double s,income; scanf("%d,%lf",&h,&s); if (h<=40) income = h*s; else if((h>=40)&&(h <= 50)) income = 40*s+(h-40)*1.5*s; el...

C语言编程问题计算薪水float work_hours=0.0f;float pay=0.0f;int day=0;const cents_per_dollar=100;int pay_in_cent=0;pay_in_cent=(int)(pay*cents_per_dollar);printf("input your pay of a w...

C语言计算工资的代码你为什么要用;if(y<5,t<=40),建议你看看逗号运算符的用法,、 int main() { int y,t; double m; scanf("%d %d",&y,&t); if(y<5 & t<=40) //且的关系 printf("%.2f",m=t*30); else i...

c语言计算时间差time.h #include clock_t _start, _end; double diff_time; _start = clock(); //-----你的过程 _end = clock(); diff_time = (double)( _end - _start ) / CLOCKS_PER_SEC;//...

C语言计算分段函数1. 代码如下,3)需要实际运行时输入测试 int main(void) { double x, y, f; printf("Please input 2 double number in the form of x y:\n"); scanf("%lf%lf", &x, &y); if(x>=0 &...

计算机二级 C语言选A 668977 #include main() { int c; while((c=getchar())!='\n') //输入2473 ,则c为相应的字符 '2'、'4'、'7'、'3' { switch(c-'2') // c-'2' 后,依次为 0,2,5,1 { case 0:...

C语言的typedef struct s ss的意义#include<stdio.h> struct s { int a; char c; }; typedef struct s ss; void main() { ss k; k.a=1; k.c='A'; printf("%d,%c\n",k.a,k.c); } //typedef 是给类型 弄个别名...

计算机c语言编程我编了这个程序,不涉及小时分钟的加减在十进制里这么转换。 小时就是(time2-time1)/100; 分钟就是后2位的相减,如果为负的话,向高位借位加60就行了 #include<stdio.h> main() {in...

C语言编程问题:使用函数计算两点间的距离#include <stdio.h> #include <math.h> double dist( double x1, double y1, double x2, double y2 ); int main() { double x1, y1, x2, y2; scanf("%lf %lf %lf %lf", &x1,...