一,本月有几天?
#include<iostream>
using namespace std;
int main()
{
int x,y,z;
cout<<"请输入年份";
cin>>x;
cout<<"请输入月份";
cin>>y;
if (y==1||y==3||y==5||y==7||y==8||y==10||y==12)
{
z=31;
}
else if(y==4||y==6||y==9||y==11)
{
z=30;
}
else if( y==2,x%400==0 || (x%4==0 && x%100!=0))
{
z=29;
}
else
z=28;
cout<<x<<"年"<<y<<"月有"<<z<<"天\n";
return 0;
}
二 定期存款利息计算器
#include <iostream>
using namespace std;
int main()
{
double x,y,z;
int h;
cout<<"欢迎使用利息计算器!\n"<<"请输入存款金额";
cin>>x;
cout<<"======存款期限======\n";
cout<<"1.3个月\n"<<"2.6个月\n"<<"3.一年\n"<<"4.二年\n"<<"5.三年\n"<<"6.五年\n";
cout<<"请输入存款期限的代号:";
cin>>h;
switch(h)
{
case 1:y=x*0.031*0.25;break;
case 2:y=x*0.033*0.5;break;
case 3:y=x*0.035*1;break;
case 4:y=x*0.044*2;break;
case 5:y=x*0.05*3;break;
case 6:y=x*0.055*5;break;
}
z=y+x;
cout<<"到期利息为:"<<y<<",本息合计共"<<z<<"元。";
<pre name="code" class="cpp" style="color: rgb(51, 51, 51); font-size: 14px; line-height: 26px;"> return 0;
}
三,数列
#include<cmath>
#include <iostream>
using namespace std;
int main()
{
int x,y;
cout<<"请输入x的值:";
cin>>x;
if(x<2)
y=x;
else if(x>=2&&x<6)
y=x*x+1;
else if(x>=6&&x<10)
y=sqrt(x+1);
else
y=1/(x+1);
cout<<"y="<<y;
return 0;
}