
求s=x+x^2+x^3+......+x^n,用递归法写C++程序 10
展开全部
#include <stodi.h>
#include<math.h>
void main()
{
int i,x,n,t,s;
printf("Plsase input of value of x and n:\n");
scanf("%d %d",&x,&n);
s=0;
for(i=1;i<=n;i++)
t=pow(x,i);
s=s+t;
printf("s=%d\n");
}
好久没做了,不知道对不对,我没有验证
#include<math.h>
void main()
{
int i,x,n,t,s;
printf("Plsase input of value of x and n:\n");
scanf("%d %d",&x,&n);
s=0;
for(i=1;i<=n;i++)
t=pow(x,i);
s=s+t;
printf("s=%d\n");
}
好久没做了,不知道对不对,我没有验证
更多追问追答
追问
怎么显示零?
追答
我没算具体对不对,不过思路肯定就这样的,你也可以用指针做,要是出现零的话,估计是什么地方赋值出错了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询