一.本月有几天
#include<iostream>
using namespace std;
int main()
{
int month,year,days;
cout<<"请输入年份,月份:"<<endl;
cin>>year>>month;
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
days=31;
else if(month==4||month==6||month==9||month==11)
days=30;
else
{
if((year%4==0&&year%100!=0)||year%400==0)
days=29;
else
days=28;
}
}
cout<<"天数为:"<<days<<"天"<<endl;
return 0;
}
二.定期存款利息计算器
#include<iostream>
using namespace std;
int main()
{
int m,x;
cout<<"欢迎使用利息计算器\n";
cout<<"请输入存款金额=";
cin>>m;
cout<<"==========存款期限===========\n";
cout<<"1、3个月\n";
cout<<"2、6个月\n";
cout<<"3、一年\n";
cout<<"4、两年\n";
cout<<"5、三年\n";
cout<<"6、五年\n";
cout<<"请输入存款期限代号:";
cin>>x;
switch(x)
{
double a,z;
case 1:a=m*0.031*0.25,z=m+a;
cout<<"到期利息:"<<a<<"元,本息合计共:"<<z<<"元。"<<endl;break;
case 2:a=m*0.033*0.5,z=m+a;
cout<<"到期利息:"<<a<<"元,本息合计共:"<<z<<"元。"<<endl;break;
case 3:a=m*0.035*1,z=m+a;
cout<<"到期利息:"<<a<<"元,本息合计共:"<<z<<"元。"<<endl;break;
case 4:a=m*0.044*2,z=m+a;
cout<<"到期利息:"<<a<<"元,本息合计共:"<<z<<"元。"<<endl;break;
case 5:a=m*0.05*3,z=m+a;
cout<<"到期利息:"<<a<<"元,本息合计共:"<<z<<"元。"<<endl;break;
case 6:a=m*0.055*5,z=m+a;
cout<<"到期利息:"<<a<<"元,本息合计共:"<<z<<"元。"<<endl;break;
default:cout<<"error\n";
}
cout<<"感谢您的使用,欢迎下次光临!\n";
return 0;
}
三.多分数段函数求值
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double x,y;
cout<<"请输入x=";
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/(x+1);
cout<<"y="<<y<<endl;
return 0;
}