}
1.9题
#include
using namespace std;
int main()
{
int a,b,c;
int add(int x,int y);
cin>>a>>b;
c=add(a,b);
cout<<"a+b="<return 0;
}
int add(int x,int y)
{int z;
z=x+y;
return(z);
}
2.3题
#include
using namespace std;
int main()
{char c1='a',c2='b',c3='c',c4='\101',c5='\116'; cout<cout<<"\t\b"<return 0;
}
2.4题
#include
using namespace std;
int main()
{char c1='C',c2='+',c3='+';
cout<<"I say: \""<cout<<"\t\t"<<"He says: \"C++ is very interesting!\""<< '\n';
return 0;
}
2.7题
#include
using namespace std;
int main()
{int i,j,m,n;
i=8;
j=10;
m=++i+j++;
n=(++i)+(++j)+m;
cout<
return 0;
}
2.8题
#include
using namespace std;
int main()
{char c1='C', c2='h', c3='i', c4='n', c5='a';
c1+=4;
c2+=4;
c3+=4;
c4+=4;
c5+=4;
cout<<"password is:"<}
3.2题
#include
#include
using namespace std;
int main ( )
{float h,r,l,s,sq,vq,vz;
const float pi=3.1415926;
cout<<"please enter r,h:";
cin>>r>>h;
l=2*pi*r;
s=r*r*pi;
sq=4*pi*r*r;
vq=3.0/4.0*pi*r*r*r;
vz=pi*r*r*h;
cout<cout<<"l= "<cout<<"s= "<cout<<"sq="<cout<<"vq="<cout<<"vz="<return 0;
}
3.3题
#include
using namespace std;
int main ()
{float c,f;
cout<<"请输入一个华氏温度:";
cin>>f;
c=(5.0/9.0)*(f-32); //注意5和9要用实型表示,否则5/9值为0
cout<<"摄氏温度为:"<return 0;
};
3.4题
#include
using namespace std;
int main ( )
{char c1,c2;
cout<<"请输入两个字符c1,c2:";
c1=getchar(); //将输入的第一个字符赋给c1 c2=getchar(); //将输入的第二个字符赋给c2 cout<<"用putchar函数输出结果为:";
putchar(c1);
putchar(c2);
cout<cout<<"用cout语句输出结果为:";
cout<return 0;
}
3.4题另一解
#include
using namespace std;
int main ( )
{char c1,c2;
cout<<"请输入两个字符c1,c2:";
c1=getchar(); //将输入的第一个字符赋给c1 c2=getchar(); //将输入的第二个字符赋给c2 cout<<"用putchar函数输出结果为:";
putchar(c1);
putchar(44);
putchar(c2);
cout<cout<<"用cout语句输出结果为:";
cout<return 0;
}
3.5题
#include
using namespace std;
int main ( )
{char c1,c2;
int i1,i2; //定义为整型
cout<<"请输入两个整数i1,i2:";
cin>>i1>>i2;
c1=i1;
c2=i2;
cout<<"按字符输出结果为:"<return 0;
}
3.8题
#include
using namespace std;
int main ( )
{ int a=3,b=4,c=5,x,y;
cout<<(a+b>c && b==c)<cout<<(a||b+c && b-c)<cout<<(!(a>b) && !c||1)<cout<<(!(x=a) && (y=b) && 0)<cout<<(!(a+b)+c-1 && b+c/2)<return 0;
}
3.9题
include
using namespace std;
int main ( )
{int a,b,c;
cout<<"please enter three integer numbers:";
cin>>a>>b>>c;
if(a