ksdf.net
当前位置:首页>>关于输入一个正整数n,计算1-1/4+1/7-1/10+1/13-1/16+....的资料>>

输入一个正整数n,计算1-1/4+1/7-1/10+1/13-1/16+....

#include int main(void) { float sum=0; int n,i; scanf("%d",&n); for(int i=1;i

#include #include int main() { int n,i,fu=1; float d=1,s=0.0; printf_s("请输入正整数n: "); scanf_s("%d",&n); for(i=1;i=n+1) printf_s("\n所求前n项和s=%5.2f\n\n",s); return 0; } 运行示例:

#includeint main(){ int i,j; double add = 0; printf("Please input a number!"); scanf("%d",&i); for(j = 0;j < i;j++) { if(j%2) add -= 1 / (double)(1 + j * 3); else add += 1 / (double)(1 + j * 3); } printf("The result is %f",add)...

#include int main() { int i,n=0; float s=0; printf("Input n:\n"); scanf("%d",&n); for (i=1;i

#include int main(void) { float sum=0,m=1; int n; printf("请输入项数: "); scanf("%d",&n); for(int i=1;i

#include main( ) { int denominator , flag,i, n; double item,sum; printf(“Enter n:”); scanf(“%d”,&n); denominator = 1; flag=1; sum = 0 for(i = 1; i

#include int main() { int n; int i; int sum = 0; int tmp = 1; scanf("%d", &n); // 输入n for (i = 1; i

此题最好用公式计算,循环的话就太笨拙了 可以看出来相邻两项合在一起就是-2,也就是说平均每一项-1, 再把奇数项的情况考虑进去,可以得出公式, 首先可以用(n+1)/2算出项数,设为x 然后如果是偶数项,答案就是-x 如果是奇数项,把最后一项算进...

{temp=2*n-1; 改成 {temp=2*i-1; import java.util.Scanner; public class Test40005 { public static void main(String[] args) { int ri, repeat; int i, n, temp; float sum = 0; Scanner in = new Scanner(System.in); repeat = in.nextInt(...

int i,sum=0,a=1; for(i=1;i

网站首页 | 网站地图
All rights reserved Powered by www.ksdf.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com