作业一
一、问题及代码
*文件名:0.cpp
*作者:程志清
*完成日期:2017年3月12日
*版本号:5.11
*对任务及其完成方法的描述部分:
*输入描述:X
*问题描述:
【项目4】多分段函数求值
*程序输出:Y
*问题分析:
*算法设计:略
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double x,y;
cout<<"请输入X的值\n";
cin>>x;
if(x<2)
{
y=x;
}
else if(x<6)
{
y=x*x+1;
}
else if(x<10)
{
y=sqrt(x+1);
}
else y=1.0/(x+1);
cout<<"y的值为:"<<y;
cin.get();
return 0;
}
二、运行结果
作业二
一、问题及代码
*文件名:0.cpp
*作者:程志清
*完成日期:2017年3月12日
*版本号:5.11
*对任务及其完成方法的描述部分:
*输入描述:
*问题描述:
【项目8】 贪财的富翁
*程序输出:
*问题分析:
*算法设计:略
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double x,y=0;
x=100000*30;
for(int i=0;i<30;i++)
{
y+=pow(2,i)*0.02;
}
cout<<"陌生人给富翁共:"<<x<<endl;
cout<<"富翁给陌生人共:"<<y<<endl;
if(x>y)
{
cout<<"富翁更划算\n";
}
else cout<<"富翁不划算\n";
return 0;
}
二、运行结果