编写函数求x1+ x2+ x3+…+xn

#include<stdio.h>
#include<math.h>
double fun3(int x,int n)
{
 double sum=0;
 for(int i=1;i<=n;i++)
 sum+=pow(x,i);
 return sum;
 
}
int main()
{
 int x, a;
 printf("Please enter two number:");
 scanf("%d %d",&x,&a);
 printf("%lf",fun3(x,a));
}

猜你喜欢

转载自blog.csdn.net/qq_44365861/article/details/89143819
今日推荐