成长历程
sasaxie
山东临沂人,开发后端多年,打算从零开始整理编程知识
展开
-
3_shuangjingdu.cpp
//2012-9-29 16:58:26#include #include using namespace std;int main(){ int b = 123456; cout<<setiosflags(ios::left)<<b<<endl; cout<<hex<<b<<endl; cout<<dec<<b<<endl; cout<原创 2012-10-15 11:59:19 · 697 阅读 · 0 评论 -
4_This is a C++ program.cpp
/*时间:2012年9月24日10:27:33目的:输出“This is a C++ program.”*/#include //包含头文件iostreamusing namespace std; //使用C++的命名空间stdint main(){ cout<<"This is a C++ program.\n";原创 2012-10-15 12:00:29 · 1186 阅读 · 0 评论 -
5_包含类的C++程序.CPP
#include //预处理指令using namespace std;class Student//声明一个类,类名为Student{private://以下为类中的私有部分 int num;//私有变量num int score;//私有变量scorepublic://以下为类中公有部分 void setdata()//定义公用函数setdata {原创 2012-10-15 12:06:12 · 685 阅读 · 0 评论 -
6_变量的命名.cpp
#include //预处理指令using namespace std;class Student//声明一个类,类名为Student{private://以下为类中的私有部分 int num;//私有变量num int score;//私有变量scorepublic://以下为类中公有部分 void setdata()//定义公用函数setdata {原创 2012-10-15 12:07:18 · 571 阅读 · 0 评论 -
7_常变量.cpp
//2012年9月25日17:26:44#include using namespace std;int main(){ const int a = 1; cout<<a<<endl; cout<<sizeof a;//使用sizeof得到a的长度 cout<<endl; return 0;}/*在VC++6.0中运行的结果是:-原创 2012-10-15 12:07:55 · 502 阅读 · 0 评论 -
9_逗号运算符的赋值.cpp
//2012年10月11日7:45:32#include using namespace std;int main(){ int a, b; b = (a = 3*5, a*4);//先执行赋值语句,再执行逗号运算符,逗号表达式的值为最后一个表达式的值 cout<<"a = "<<a<<","<<"b = "<<b<<endl; return 0;原创 2012-10-15 12:08:59 · 784 阅读 · 0 评论 -
10_各行小数点对齐.cpp
//2012-9-29 17:07:56#include #include using namespace std;int main(){ double a = 123.456, b = 3.14159, c = -3214.67; cout<<setiosflags(ios::fixed)<<setprecision(2)<<setiosflags(i原创 2012-10-15 12:09:29 · 970 阅读 · 0 评论 -
13_将字符赋给整型变量.cpp
#include using namespace std;int main(){ int i, j; i = 'A';//将一个字符常量赋给整型变量i j = 'B';//将一个字符常量赋给整型变量j cout<<i<<' '<<j<<'\n';//输出整型变量i和j的值 return 0;}/*在VC++6.0中运行的结果是:---原创 2012-10-15 12:11:18 · 971 阅读 · 0 评论 -
关于“-128的补码补码问题”理解
关于“-128的补码补码问题”理解申明:来源于《80X86汇编语言程序设计》作者:沈美明温冬婵清华大学出版社出版 在这本书中的第6-7页中的“计算机中数和字符的表示”一节中有如下解释:补码表示法中正数 补码表示法中正数采用符号-绝对值表示,即数的最高有效位为0表示符号为正,数的其余部分则表示数的绝对值。例如,假设机器字长为8位,则[+1]补=0000转载 2012-10-15 12:13:33 · 1320 阅读 · 0 评论 -
16_强制类型转换.cpp
/*2012年9月26日10:13:54*/#include using namespace std;int main(){ float x; int i; x = 3.6; i = (int)x; cout<<"x = "<<x<<",i = "<<i<<endl; return 0;}/*在VC++6.0中运行的结原创 2012-10-15 16:10:58 · 605 阅读 · 0 评论 -
18_求两者中较大者_1.cpp
#include //包含头文件iostreamusing namespace std;//命名空间stdint max(int x, int y)//定义max函数,函数值为整型,形式参数x,y为整型{ //max函数体开始 int z; //声明变量,定义本函数中用到的变量z为整型 if (x>y) z =原创 2012-10-15 16:12:16 · 1012 阅读 · 1 评论 -
15_两个表达式.cpp
//2012-10-11 7:55:40#include using namespace std;int main(){ int a, x, y; x = (a=3,6*3); cout<<"a = "<<a<<endl; cout<<"x = "<<x<<endl; y = (x = a = 3, 6*a); cout<<"a = "<<a原创 2012-10-15 16:10:17 · 503 阅读 · 0 评论 -
8_递归.cpp
#include // 预编译命令using namespace std;int step=1; // 整型全局变量,预置1,步数void move(int, char, char, char); // 声明要用到的被 调用函数int main() // 主函数{ // 主程序开始 int n;原创 2012-10-15 12:08:29 · 672 阅读 · 0 评论 -
11_根据变量的类型从输入流中提取相应长度的字节.cpp
#include using namespace std;int main(){ char c1, c2; int a; float b; cin>>c1 >>c2 >>a >>b; cout<<c1 <<c2 <<a <<b <<endl; return 0;}原创 2012-10-15 12:10:18 · 614 阅读 · 0 评论 -
12_计算货款,使用符号常量.cpp
/*时间:2012年9月25日17:10:24目的:符号常量的使用*/#include using namespace std;#define PRICE 30//注意这不是语句,末尾不要加“;”int main(){ int num, total; num = 10; total = num * PRICE;//PRICE是符号常量,代原创 2012-10-15 12:10:47 · 1164 阅读 · 1 评论 -
14_可以求字符的ASCII.cpp
//2012年9月29日17:30:22#include using namespace std;int main(){ cout<<getchar()<<endl; return 0;}//可以求字符的ASCII码原创 2012-10-15 16:09:21 · 685 阅读 · 0 评论 -
17_求a和b之和.cpp
/*时间:2012年9月24日10:40:50目的:求a和b之和*/#include //包含头文件iostreamusing namespace std; //使用命名空间stdint main(){ int a,b,sum; //定义整形变量a,b,sum cin>原创 2012-10-15 16:11:46 · 1283 阅读 · 0 评论 -
21_求一元二次方程的根_完整版
//2012-9-29 17:54:07#include #include using namespace std;int main(){ float a, b, c, x1, x2, d; cout<<"请输入a,b,c的值:"<<endl; cin>>a>>b>>c; d = b*b-4*a*c; if (d>0) { x1 =原创 2012-10-16 16:33:25 · 1364 阅读 · 0 评论 -
29_用scanf和printf函数进行输入和输出.cpp
//2012-9-29 17:40:31#include using namespace std;int main(){ int a; float b; char c; scanf("%d %f %c", &a, &b, &c);//如果用“%d,%f,%c”的话,则输入的时候必须用“,”隔开! printf("a = %d, b = %f, c =原创 2012-10-17 12:07:05 · 1250 阅读 · 0 评论 -
20_求一元二次方程的根
//2012年9月29日17:46:17#include #include using namespace std;int main(){ float a, b, c, x1, x2; cin>>a>>b>>c; x1 = (-b + sqrt(b*b-4*a*c))/(a*2); x2 = (-b - sqrt(b*b-4*a*c))/(a*2原创 2012-10-16 16:32:26 · 1607 阅读 · 0 评论 -
2_i love you.cpp
#include using namespace std;int main(){ char y; char x, z; x = 3; z = 1; cout<<'\t'<<'\t'<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x<<x原创 2012-10-15 11:57:16 · 828 阅读 · 1 评论 -
1_【重要】判断一个数是否为回文数.cpp
# include int main(void){ int val;//存放待判断的数字 int sum = 0; int m; printf("请输入需要判断的数字:"); scanf("%d", &val); m = val; while (m) { sum = sum*10 + m%10; m /=10; } i原创 2012-10-15 12:14:23 · 1355 阅读 · 0 评论 -
28_下面是整数输出的例子.cpp
//2007年9月29日12:58:22#include #include using namespace std;int main(){ int b = 123456; cout<<b<<endl; cout<<hex<<b<<endl; cout<<setiosflags(ios::uppercase)<<b<<endl; cout原创 2012-10-17 12:06:33 · 767 阅读 · 0 评论 -
19_求两者中较大者_2
/*时间:2012年9月25日12:26:16目的:求两者中的大者*/#include //包含头文件iostreamusing namespace std;//使用命名空间stdint main()//主函数{ int max(int x, int y);//对max函数作声明 int a, b, c;//定义整型变量 cin>>a>>b;//原创 2012-10-16 16:31:34 · 1305 阅读 · 0 评论 -
26_问题.cpp
//2011年9月28日14:30:44#include using namespace std;int main(){ cout<<"We must study C\ ++ hard!";//第二行没有空格!! cout<<endl; return 0;}/*在VC++6.0中运行的结果是:-------------------原创 2012-10-17 12:05:10 · 848 阅读 · 0 评论 -
23_输出三者中的较小值.cpp
#include using namespace std;int main(){ int a, b, c; int f(int x, int y, int z); cin>>a>>b>>c; c = f(a, b, c); cout<<c<<endl; return 0;}int f(int x, int y, int z){原创 2012-10-17 12:01:38 · 580 阅读 · 0 评论 -
24_输出双精度数.cpp
//2007-9-29 12:48:18#include #include //使用控制符必须加头文件,否则会出错!using namespace std;int main(){ double a = 123.456789012345; cout<<a<<endl; cout<<setprecision(9)<<a<<endl; cout<<原创 2012-10-17 12:02:30 · 1080 阅读 · 0 评论 -
25_输入单个字符.cpp
//2012年9月29日17:26:59#include using namespace std;int main(){ char c; c = getchar(); putchar(c + 32);//ASCII码相加后输出得到的字符 putchar('\n'); return 0;}原创 2012-10-17 12:04:09 · 904 阅读 · 0 评论 -
27_下面是一个完整的C++程序.CPP
//2007年9月28日10:10:07#include //预处理指令using namespace std;//在函数之外的全局声明int a = 3;//在函数之外的全局声明int main()//函数首部{ float b;//函数内部的声明 b = 4.5;//执行语句 cout<<a<<endl<<b<<endl;//执行语句 r原创 2012-10-17 12:06:00 · 1160 阅读 · 2 评论 -
30_有符号数据传送给无符号变量
//2012年9月26日11:12:17#include using namespace std;int main(){ unsigned short a; short b = -1; a = b; cout<<"a = "<<a<<endl; return 0;}/*在VC++6.0中运行的结果是:------------原创 2012-10-18 16:16:30 · 964 阅读 · 0 评论 -
31_字符数据与整数进行算数运算
//时间:2012年9月25日16:52:58#include using namespace std;int main(){ char c1, c2; c1 = 'a'; c2 = 'b'; c1 = c1 - 32; c2 = c2 - 32; cout<<c1<<' '<<c2<<endl; return 0;}/*原创 2012-10-18 16:16:59 · 975 阅读 · 0 评论 -
32_字符与整型的赋值
//2012年9月26日10:37:091#include using namespace std;int main(){ short int i; i = 289; char c; c = i; int x; x = c; cout<<c<<" "<<x<<endl; return 0;}/*在VC++6.0中运行原创 2012-10-18 16:17:28 · 777 阅读 · 0 评论 -
C++_有默认参数的函数
/***************************时间:2012-10-17 10:49:44**描述:有默认参数的函数 ***************************/# include using namespace std;int main(){ int max(int a, int b, int c = 0);//函数声明,形参原创 2012-10-29 15:58:17 · 575 阅读 · 0 评论 -
C++_函数的重载求两个数或三个数的最值
/*******************************时间:2012年10月17日10:19:52 **描述:函数的重载 *******************************/# include using namespace std;int main(){ int max(int a, int b, int原创 2012-10-29 15:59:29 · 15740 阅读 · 2 评论 -
C++_静态局部变量求阶乘
/*******************************时间:2012年10月17日11:09:02 **描述:静态局部变量,求阶乘 *******************************/# include using namespace std;int fac(int);//函数声明int main(){ int i;原创 2012-10-29 16:01:02 · 2685 阅读 · 0 评论 -
C++_静态局部变量的值在函数结束后不会释放,也不会被外部调用
/************************************************************************时间:2012年10月17日11:00:32 **描述:静态局部变量,函数结束后,内存空间仍被保留,但不能被函数外部调用********************原创 2012-10-29 16:03:23 · 9221 阅读 · 0 评论 -
C++_数组的使用简单举例_输入与输出
# include /******************************时间:2011年3月3日15:12:32 **描述:数组的输入与输出 ******************************/using namespace std;int main(){ int i, a[10]; cout<<"请输入10个整数:\原创 2012-10-29 16:05:39 · 12174 阅读 · 1 评论 -
76_用数组来处理Fibonacci数列问题.cpp
/******************************时间:2012年10月17日18:55:45**描述:数组 ******************************/# include # include using namespace std;int main(){ int i; int原创 2012-10-29 16:07:04 · 1721 阅读 · 0 评论 -
1_China转Glmre.cpp
#include using namespace std;int main(){ char c1, c2, c3, c4, c5; c1 = 'C'; c2 = 'h'; c3 = 'i'; c4 = 'n'; c5 = 'a'; c1 = c1 + 4; c2 = c2 + 4; c3 = c3 + 4; c4 = c4 + 4原创 2012-10-15 11:55:26 · 2141 阅读 · 0 评论 -
36_关系运算符的优先级
/* 时间:2012-10-12 21:53:04 目的:关系运算符的执行顺序*/# include using namespace std;int main(void){ int a = 3, b = 2, c = 1; int d, f; d = a > b; f = a > b > c;//>是从左到右执行的,先执行a>b为真,值为1,原创 2012-10-19 19:59:38 · 576 阅读 · 0 评论