#include<iostream>#include<limits>usingnamespace std;externint a, b;externint c;externfloat f;intmain(int argc,char**argv){int a, b, c;float f;
a =10;
b =20;
c = a + b ;
cout << c << endl;
f =70.0/3.0;
cout << f << endl;return0;}
Less-3:
#include<iostream>usingnamespace std;intmain(int argc,char**argv){unsignedint a =60;// 60 = 0011 1100unsignedint b =13;// 13 = 0000 1101int c =0;
c = a <<2;
cout <<"Line 1 - c 的值是"<< c << endl;
c = a >>2;
cout <<"Line 2 - c 的值是"<< c << endl;
cout <<sizeof(c)<< endl;return0;}
Less-4:
#include<iostream>usingnamespace std;intmain(int argc,char**argv){int a, b, c;char ch;
cin >> a >> ch >> b >> c;
cout << a << endl
<< ch << endl
<< b << endl
<< c;return0;}
#include<iostream>usingnamespace std;int i =0;intmain(){int i =5;{int i =7;
cout <<"::i="<<::i << endl;
cout <<"i="<< i << endl;::i =1;
cout <<"::i="<<::i << endl;}
cout <<"i="<< i << endl;
cout <<"please input x,y: ::i= "<<::i << endl;
i +=::i;::i =100;
cout <<"i="<< i << endl;
cout <<"::i="<<::i << endl;return0;}
Less-7:
#include<iostream>usingnamespace std;voidf(double x =50.6,int y =10,char z ='A');intmain(){double a =216.34;int b =2;char c ='E';f();f(a);f(a, b);f(a, b, c);return0;}voidf(double x,int y,char z){
cout <<"x="<< x <<'\t'<<"y="<< y <<'\t';
cout <<"z="<< z << endl;}
Less-8:
#include<iostream>usingnamespace std;int&s(constint&a,int&b){
b += a;return b;}intmain(){int x =500, y =1000, z =0;
cout << x <<'\t'<< y <<'\t'<< z <<'\t'<< endl;s(x, y);
cout << x <<'\t'<< y <<'\t'<< z <<'\t'<< endl;
z =s(x, y);
cout << x <<'\t'<< y <<'\t'<< z <<'\t'<< endl;s(x, y)=200;
cout << x <<'\t'<< y <<'\t'<< z <<'\t'<< endl;return0;}
Less-9:
#include"iostream"usingnamespace std;voidfun(int x,int y){
x += y;
y += x;}intmain(){int x =5, y =10;fun(x, y);fun(y, x);
cout <<"x="<< x <<",y="<< y << endl;return0;}
Less-10:
#include<iostream>usingnamespace std;intadd(int a,int b);intmain(int argc,char**argv){int x, y, sum;
cout <<"Please input x and y :"<< endl;
cin >> x >> y;
sum =add(x, y);
cout <<"Please input x and y : "<< x <<"+"<<y <<" = "<< sum << endl;return0;}intadd(int a,int b){return a+b ;}
#include<iostream>#include<iomanip>#include<cmath>#include<ctime>usingnamespace std;constint N =10;intmain(int argc,char**argv){int*r,*sum, i;
sum =newint(0);
r =newint[10];if(r ==NULL){
cout <<"allocation failure.\n";return0;}srand(time(NULL));for(int i =0; i < N; i++){
r[i]=rand()%10000-3000;if(r[i]<0)(*sum)++;}for(int i =0; i < N; i++){
cout <<setw(4)<< r[i]<< endl;}
cout <<"the number of negative number: "<<*sum << endl;
cout <<"the number of positive number: "<< N -*sum << endl;delete[] r;delete sum;return0;}