include "stdio.h"int main(void){ int n,i,a,b;double sum;while(1){printf("Input n(int n>0)...\nn=");if(scanf("%d",&n) && n>0)break;printf("Error, must n>0: ");}for(sum=0.0,a=1,b=2,i=1;i<=n;i++){sum+=b/(a+0.0);b+=a;a=b-a;}printf(...
(n>10且为偶数)\n"); scanf("%d",&n); } for(i=2;i<=n;i+=2){ s+=i; } printf("数列的和为:%d\n",s);}
你写的这个公式只能求首项为1,公差为1的等差数列的前n项和。对于一般等差数列,这个公式是求不了的。代码如下:include <stdio.h>void main(){int n;printf("请输入等差数列的项数n: ");scanf("%d",&n);printf("%d",n*(n+1)/2);} ...
include<stdio.h>#include<math.h> //没有必要加载int main(){double n,i,sum,y,a=1; //对a赋初值1,不需要变量ywhile(scanf("%lf",&n)!=EOF){sum = 0;for(i=1;i<=n;i++){ //增加大括号//y = n+1;//此句删除//a = pow(-1,y);//此句删除sum = sum+(1.0/i*...
int main( void ){ int n; // 项数 float sum = 0; //和 printf( "输入一个整数:\n" );scanf( "%d", &n );if ( n < 0 ) // 处理错误输入 { printf( "error\n" );return 0;} else { int m_1 = 0;int m_2 = 1;for ( int i = 1; i <=n ; i ++ ){ sum...
我修改一下一楼的答案…include<stdio.h> void main(){ int a=2;int b=0;while(b<9000){ a=a*2;b=b+a;} printf("b=%d";&b);}
C语言;while 语句 输入M个数,去除最大值和最小值,求剩余数的平均值,M取无穷大且为任意值. #include <stdio.h> #include <conio.h> void main( 在C++中用递归函数求fibonacci数列第46个数的值,花了近30秒,有没有更快点的方法? int fib(int n){ if( n == 1 || n == 2 )&nbs 2023自考大专考...
include <stdio.h>void main(){int i,n;double s=0;scanf("%d",&n);for(i=1;i<=n;i++)s+=(1.0/(2*i-1)-1.0/(2*i+1))/2;printf("%lf",s);}
int n){ if(n == 1) return 6; else return aimsum(n-1) + n*(n+1)*(n+2);}int main(){ int n,sum,i; sum = 0; scanf("%d",&n);// input n for(i=1;i<=n;++i) { sum += i*(i+1)*(i+2); } printf("1*2*3+3*4...
其他情况得0,因为"/"对于int型数据来说,除后取整操作,即10/9=1.111111...,那么实际结果为1,小数点后的全部丢弃(不是四舍五入,而是全舍)要想得到你要的结果应该这样 1.0 * i / deno //1.0是double型的,与i相乘还得double型的,这样就能出正确结果 或 ((double) i ) / deno ...