在线求c++的编程答案 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/04 17:02:58
已知y=1+x/2+x²/3+...+x的9次方/10编写一个程序,求x每取一个值时所对应的y值,其中x的每个值由键盘输入,直到输入终止标准100为止

#include <iostream>
#include <cmath>
using namespace std;

double getResult(double x)
{
double y = 1.0;
for(int i=1; i<=9; i++)
y = y+pow(x,i)/(i+1);
return y;
}

int main()
{
int x;
cout<<"请输入x的值:"<<endl;
cin>>x;
if(x == 100)
return 0;
double y = getResult(x);
cout<<"The result is: "<<y<<endl;

return 0;
}

#include<stdio.h>
#include<math.h>
void main(){
double x,y,i;
for(;;){
scanf("%d",&x);
if(x==10)break;y=1;
for(i=1;i<10;i++){
y+=pow(x,i)/(i+1);
}printf("%lf\n",y);
}
}

#include<iostream>
using namespace std;
main()
{
float y=1,x,sq=1;
cout <<"Input x." <<endl;
cin