3136:【例23.1】 后天星期
#include<bits/stdc++.h>
using namespace std;
int main()
{
int ans;
cin>>ans;
if( ans+2>7 )
{
cout<<ans+2-7<<endl;
}
else
{
cout<<ans+2<<endl;
}
return 0;
}
3137:【例23.2】 这个月有几天
#include<bits/stdc++.h>
using namespace std;
int main()
{
int y,m;
cin>>y>>m;
int a[12+1]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if( m!=2 )
{
cout<<a[m]<<endl;
}
else
{
if( (y%4==0 && y%100!=0) || y%400==0 )
{
cout<<a[m]+1<<endl;
}
else
{
cout<<a[m]<<endl;
}
}
return 0;
}
3138:【例23.3】 简单计算器
[例 23.3] 简单计算器
1057:简单计算器
2058:【例3.10】简单计算器
#include<bits/stdc++.h>
using namespace std;
int main()
{
int ans,num;
char ch;
cin>>ans>>num>>ch;
if( ch=='+' )
{
cout<<ans+num<<endl;
}
if( ch=='-' )
{
cout<<ans-num<<endl;
}
if( ch=='*' )
{
cout<<ans*num<<endl;
}
if( ch=='/' )
{
if( num!=0 )
{
cout<<ans/num<<endl;
}
else
{
cout<<"Divided by zero!"<<endl;
}
}
if( ch!='+' && ch!='-' && ch!='*' && ch!='/' )
{
cout<<"Invalid operator!"<<endl;
}
return 0;
}
3139:练23.1 成绩等级
第25课 成绩等级 《小学生C++趣味编程》
#include<bits/stdc++.h>
using namespace std;
int main()
{
int ans;
cin>>ans;
if( ans>=90 )
{
cout<<"A"<<endl;
}
if( ans<90 && ans>=70 )
{
cout<<"B"<<endl;
}
if( ans<70 && ans>=60 )
{
cout<<"C"<<endl;
}
if( ans<60 )
{
cout<<"D"<<endl;
}
return 0;
}
3140:练23.2 王宅六味
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
switch(n){
case 1:
cout<<"寿仙菇";
break;
case 2:
cout<<"酒糟芋";
break;
case 3:
cout<<"下山笋";
break;
case 4:
cout<<"太师豆腐";
break;
case 5:
cout<<"孝子鱼";
break;
case 6:
cout<<"猪全福";
break;
default: cout<<"无此编号的菜";
}
return 0;
}