bycj.net
当前位置:首页 >> C语言编写程序输入一实数x和一整数n,求x+x^2+x^3+... >>

C语言编写程序输入一实数x和一整数n,求x+x^2+x^3+...

#include <stdio.h> int main() { int n, i; float x, t = 1.0, s = 0.0; scanf("%f %d", &x, &n); for (i = 1; i <= n; i ++) { t *= x; s += t; } printf("%f\n", s); }

nain(){int n,i;float sum=1,x,y;scanf("%f%d",&x,&n);y=1;for(i=1;i<=n;i++){y*=x;sum+=y;}printf("result=%f\bain");}有什么du问zhi题请dao留内言.容

#includefloat x;int n,i;float s=1.0;void main(){printf("Please Input x:");scanf("%f",&x);printf("Please Input num:");scanf("%d",&n);if(n

scanf("%f %d",&x,&n);多了空格改为:scanf("%f%d",&x,&n);

#include<stdio.h> float x; int n,i; float s=1.0; void main() { printf("Please Input x:"); scanf("%f",&x); printf("Please Input num:"); scanf("%d",&n); if(n<0) printf("n must greater than 0."); else if(n==0) s=1; else { for(i=1;i<=n;i++) { s=s*x; } } printf("%f\n",s); }

#include "math.h" void main() { float n, x, y; scanf("%f%f", &x, &n); y = pow(x, n); printf("%f" , y); }

d=inputbox("输入N")x=inputbox("输入X")msgbox mcase(d,x)function mcase(d,x)for n=1 to d if n=1

#includeintpow(inta,intn);voidmain(){inta,n;registerints=0,i;printf("输入底数a\n");scanf("%d",&a);printf("输入指数n\n");scanf("%d",&n);for(i=n;i>0;i--)s=s+pow(a,i);printf("%d^1+%d^2+.+%d^%d=%d\n",a,a,a,n,s);}intpow(inta,intn){registerintc=1;for(;n>0;n--)c=c*a;returnc;}

用循环.

x^=n; x的n次方不能这样写. ^在C里是异或操作 #include <stdio.h>#include <math.h>int main(){ int x=0,y=1,n=0,s=0,z=0; scanf("%d,%d",&x,&z); s = 1; for(n=1;n<=z;n++) { y = x*y; s+=y; } printf("%d",s); return(0);}

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