1.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
const double RATE=0.005;
double cp=1.0;
double cp_up,cp_down;
cp_up=pow((cp+RATE),365);
cp_down=pow((cp-RATE),365);
cout<<"好好学习,能力值:"<<cp_up<<endl;
cout<<"每天不学,能力值:"<<cp_down<<endl;
return 0;
}
2. 编写程序,不借助中间变量完成两个变量数据值的交换
#include <iostream>
using namespace std;
int main()
{
int a,b;
cout<<"输入变量a和b的值:";
cin>>a>>b;
cout<<"交换前a="<<a<<",b="<<b<<endl;
a=a+b;
b=a-b;
a=a-b;
cout<<"交换后a="<<a<<",b="<<b<<endl;
return 0;
}
3.p63(1)
#include <iostream>
using namespace std;
int main()
{
int year;
cout<<"输入年份:";
cin>>year;
cout<<year<< "年是"<<((year%100!=0 && year%4==0 || year%400==0)?"2月份有29天":"2月份有28天") <<endl;
return 0;
}
4.(2)
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d;
cout<<"请输入两个数:";
cin>>a>>b;
c=a+b;
d=a-b;
cout<<(a>b?c:d);
return 0;
}