2-26
#include
using namespace std;
char flag;
char Israiny(char flag)
{if (flag=='Y')
{cout<<"下雨";}
else if (flag=='N')
{cout<<"没下";}}
int main()
{cout<<"下雨了么";
char a;
cin>>a;
do
{cout<<"下雨了么";
cin>>a;}
while(a!='Y' and a!='N');
if(a=='Y' or a=='N')
{Israiny(a);}}
2-27
#include
using namespace std;
int main()
{
cout<<"考了多少分";
int grade;
cin>>grade;
if(grade<=100 and grade >=90)
{
cout<<"忧";
}
else if(grade<90 and grade >=80)
{
cout<<"良";
}
else if(grade<80 and grade >=60)
{
cout<<"中";
}
else
{
cout<<"差";
}
}
2-28
(1)if …else…
#include
using namespace std;
int main()
{
cout<<"Menu:A,D,S,Q, select one:"
char a;
cin>>a;
do
{{if (a=='A')
{cout<<"添加";}
else if (a=='D')
{cout<<"删除";}
else if (a=='S')
{cout<<"排序";}}
cin>>a;
while (a!='Q');
if (a=='Q')
{cout<<"结束程序";}
}
(2)switch语句
#include
using namespace std;
int main()
{cout<<"Menu:A,D,S,Q,select one:";
char a ;
cin a;
do{
switch(a)
{case 'A':
{cout<<"添加";
cin>>a;
break;}
case 'D':
{cout<<"删除";
cin>>a;
break;}
case 'S':
{cout<<"排序";
cin>>a;
break;}
}
}
while(a!=Q);
if(a=='Q')
{cout<<"程序结束";}}
2-29
#include
using namespace std;
int number;
bool Is_Prime_Number(int number)
{
int j;
for (j=2;j
2-31
#include
using namespace std;
int main()
{
struct time{int year;
int month;
int day;
int time;
int year;}Time1;
cout<<"input year,month,day,time:";
int i;
for(i=1;i<4;i++)
{
if(i==1)
{
cin>>Time1.year;
cout<>Time1.month;
cout<>Time1.day;
cout<>Time1.time;
cout<
2-32
#include
using namespace std;
int main()
{ int number =50;
int i;
do
{ cin>>i;
{ if(i>number)
{cout<<"i>number"; }
else if(i
2-34
#include
using namespace std;
int main()
{
int i,j,k;
int sum;
sum=0;
for(i=1;i<5;i++)
for(j=1;j<5;j++)
for(k=1;k<5;k++)
{
if(i!=j && j!=k &&i!=k)
{sum=sum+1;}
}
cout<
2-35
#include
using namespace std;
int main()
{
int i,j,k;
for(i=1;i<=9;i++)
{for(j=1;j<=i;j++)
{x=i*j;
cout<