- 博客(2)
- 收藏
- 关注
原创 7-49 循环结构12:求值 (50 分)
#include<stdio.h>#include<math.h>int main(){ double s=0.0; int n=1,t; scanf("%d",&t); while(n<=t) { s=s+pow(-1,n+1)*pow(2*n-1,-1); n++; } printf("%.6f",s); return 0;}
2021-08-01 15:38:01 134
原创 7-45 循环结构7:求x+x2+x3+...+xn的值 (50 分) 输入整数x,n(x与n均为1到8之间的整数),输出x1+x2+x3+...+xn(第二个数字表示指数)的值,不能使用pow函数
#include<stdio.h>int main(){ int x,n,t=1; int s=0; int i,j; scanf("%d%d",&x,&n); for(i=1;i<=n;i++) { t=1; for(j=1;j<=i;j++) { t*=x; } s=s+t; } printf("%d",s); return 0; }
2021-08-01 13:16:35 1514
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人