#include<iostream>usingnamespace std;intmain(){int x;
cout <<"输入一个数:";
cin >> x;if(x >0) cout << x <<"是正数"<< endl;elseif(x <0) cout << x <<"是负数"<< endl;else cout << x <<"既不是正数,也不是负数"<< endl;if(x %2) cout << x <<"是奇数"<< endl;else cout << x <<"是偶数"<< endl;return0;}
#include<iostream>#include<math.h>usingnamespace std;intmain(){float x,y;
cout <<"输入x:";
cin >> x;if(x <5) y =-x +3.5;elseif(x >=5&& x <10) y =20-3.5*(x +3)*(x +3);elseif(x >=10) y = x /2-3.5+sin(x);
cout <<"y的值为:"<< y << endl;return0;}
#include<iostream>usingnamespace std;intmain(){int x,m;float y,r;
cout <<"输入奖金:";
cin >> x;
m = x /100;switch(m){case0: r =0; y =0;break;case1: r =2; y = r * x /100;break;case2:case3: r =4; y = r * x /100;break;case4:case5:case6:case7: r =8; y = r * x /100;break;default: r =10; y = r * x /100;}
cout <<"税率为:"<< r <<"%"<< endl <<"应交税款为:"<< y << endl <<"实得奖金数为:"<< x - y << endl;return0;}
#include<iostream>usingnamespace std;voidprintstar(void){
cout <<"***********\n";}voidprint_message(void){
cout <<"Hello do you do!\n";}intmain(){printstar();print_message();printstar();}
#include<iostream>usingnamespace std;intmax(int x,int y){int z;
z =(x > y)? x : y;return z;}intmain(){int a,b,c;
cin >> a >> b;
c =max(a,b);
cout <<"The max is "<< c << endl;}
#include<iostream>usingnamespace std;voidfun(int a,int b){
a = a *10;
b = b + a;
cout << a <<'\t'<< b << endl;}intmain(){int a =2,b =3;fun(a,b);
cout << a <<'\t'<< b << endl;}
#include<iostream>usingnamespace std;voidfun(int a,int b){
cout <<"a="<< a <<"b="<< b << endl;}intmain(){int x =1;fun(x,++x);return0;}
#include<iostream>usingnamespace std;int a =3,b =5;intmax(int a,int b){int c;
c = a > b ? a : b;return c;}intmain(){int a =8;
cout <<max(a,b)<< endl;}
#include<iostream>usingnamespace std;int x;voidcude(void){
x = x * x * x;}intmain(){
x =5;cude();
cout << x << endl;}
#include<iostream>usingnamespace std;intfun(int a){int c;staticint b =3;
c = a + b++;return c;}intmain(){int x =2,y;
y =fun(x);
cout << y << endl;
y =fun(x +3);
cout << y << endl;}
#include<iostream>usingnamespace std;intf(int a){int b =0;staticint c =3;
b++;
c++;return a + b + c;}intmain(){int a =2,i;for(i =0;i <3;i++)
cout <<f(a)<< endl;}
#include<iostream>usingnamespace std;intq(int x){int y =1;staticint z =1;
z += z + y++;return x + z;}intmain(){
cout <<q(1)<<'\t';
cout <<q(2)<<'\t';
cout <<q(3)<<'\t';
cout << endl;}
#include<iostream>#include<time.h>usingnamespace std;intcalc1(int a,int b){return a + b;}inlineintcalc2(int a,int b){return a + b;}intmain(){int x[1000],y[1000],z[1000];for(int i =0;i <1000;++i)for(int j =0;j <1000;++j)for(int k =0;k <1000;++k){
z[i]=calc1(x[j],x[k]);//z[i] = calc2(x[j],x[k]);}}
#include<iostream>usingnamespace std;int a;intmain(){externintpower(int);int b =3,c,d,m;
cin >> a >> m;
c = a * b;
cout << a <<"*"<< b <<"="<< c << endl;
d =power(m);
cout << a <<"**"<< b <<"="<< d << endl;}
#include<iostream>usingnamespace std;voidfun(int a){if(a <10){
cout << a;return;}else
cout << a %10;
a /=10;fun(a);}intmain(){int x;
cout <<"输入一个整数";
cin >> x;fun(x);return0;}
#include<iostream>#include<math.h>usingnamespace std;intmain(){float a,b,c,s;
cout <<"输入三角形的三边长:";
cin >> a >> b >> c;if((a + b <= c)||(a + c <= b)||(b + c <= a))
cout <<"无法构成三角形";else{
s =0.25*sqrt((a + b + c)*(a + b - c)*(a + c - b)*(b + c - a));
cout <<"面积为:"<< s << endl;}}
#include<iostream>usingnamespace std;classA{float x,y;public:voidSetxy(float a,float b){x = a;y = b;}voidPrint(void){cout << x <<'\t'<< y << endl;}}a1,a2;intmain(){
A a3,a4;}
#include<iostream>usingnamespace std;classA{float x,y;public:float m,n;voidSetxy(float a,float b){x = a;y = b;}voidPrint(void){cout << x <<'\t'<< y << endl;}};intmain(){
A a1,a2;//定义对象
a1.m =10; a1.n =20;//为公有成员数据赋值
a1.Setxy(2.0,5.0);//为私有成员数据赋值
a1.Print();}
#include<iostream>usingnamespace std;classA{float x,y;public:float m,n;voidSetxy(float a,float b){x = a;y = b;}voidPrint(void){cout << x <<'\t'<< y << endl;}};intmain(){
A a1,a2;//定义对象
a1.m =10; a1.n =20;//为公有成员数据赋值
a1.x =2,a1.y =5;
a1.Setxy(2.0,5.0);//为私有成员数据赋值
a1.Print();}
#include<iostream>usingnamespace std;classA{float x,y;public:float m,n;voidSetxy(float a,float b){x = a;y = b;}voidPrint(void){cout << x <<'\t'<< y << endl;}};intmain(){
A a1,a2;
a1.m =10,a1.n =20;//为公有成员数据赋值
a1.Setxy(2.0,5.0);
a2 = a1;
a1.Print();a2.Print();}
#include<iostream>#include<iomanip>usingnamespace std;intmain(){int i =5,j =10;
cout <<setw(6)<< i <<setw(10)<< j << endl;}
/*#include<iostream>
using namespace std;
int main()
{
float a,b,t;
cout << "Input 2 Real Number :\n";
cin >> a >> b;
if(a > b)
{
t = a;
a = b;
b = t;
}
cout << a << '\t' << b << endl;
}
*//*
#include<iostream>
using namespace std;
int main()
{
char ch;
while(cin.get(ch) && ch!='\n')
switch (ch - '2')
{
case 0:
case 1: cout << (char)(ch + 4);
case 2: cout << (char)(ch + 4);break;
case 3: cout << (char)(ch + 3);break;
default:cout << (char)(ch + 2);
break;
}
cout << endl;
}
*/#include<iostream>usingnamespace std;intmain(){int i=1,sum=0;//定义变量,初始化do//构造循环{ sum=sum+i;// 循环体,多次执行
i=i+1;}while(i<=100);
cout <<"sum="<< sum << endl;//输出结果}
#include<iostream>usingnamespace std;intmain(){int i;int result =0;for(i =1;i <=100;i++){
result += i;}
cout << result << endl;}
#include<iostream>#include<fstream>usingnamespace std;intmain(){//声明文件流对象
ofstream outFile("outFile.txt",ios::out);if(!outFile)//使用错误流对象输出错误的信息
cerr <<"Open file or create file error."<< endl;else//输出数据到与对象outFile关联的文件中
outFile <<"This is a test file.";}
#include<iostream>#include<fstream>usingnamespace std;intmain(){//声明文件流对象
ofstream outFile;
outFile.open("outFile.txt",ios::out);if(!outFile)//使用错误流对象输出错误的信息
cerr <<"Open file or create file error."<< endl;else{//输出数据到与对象outFile 关联的文件中
outFile <<"This is a test file2.";
outFile.close();}}