随笔分类 -  C&C++

摘要:#include #include void main(){ char a[16]; int ip_addr; printf("请输入IP地址:"); scanf("%s", a); /*参数nptr字符串,如果第一个非空格字符存在, 是数字或者正负号则开始做类型转换, 之后检测到非数字(包括结束符 \0) 字符时停止转换, 返回整型数。否则,返回零,*/ ip_addr = atoi(a); printf("%d\n", ip_addr); if((ip_addr >> 7) == 0) { printf(... 阅读全文
posted @ 2013-11-02 22:49 爱无限 阅读(2951) 评论(0) 推荐(0)
摘要:1 #include 2 3 #define N 100 4 5 void print1(int a[], int len) 6 { 7 int i; 8 9 for(i = 0; i = 0; j--) 49 { 50 if(a[j] > a[j + 1]) 51 { 52 Swap(&a[j], &a[j + 1]); 53 } 54 } 55 } 56 57 return 0; 58 } 59... 阅读全文
posted @ 2013-11-02 22:02 爱无限 阅读(416) 评论(0) 推荐(0)
摘要:1. 最大子序列和问题 1 int MaxSubsquenceSum(const int A[],int N){ 2 3 int ThisSum,MaxSum,j; 4 5 ThisSum = MaxSum = 0; 6 7 for(j=0;j<N;j++){ 8 9 ThisSum += A[j];10 11 if(ThisSum > MaxSum)12 13 MaxSum = ThisSum;14 15 else if(ThisSum < 0)16 17 ThisSum = 0;18 19... 阅读全文
posted @ 2013-05-13 19:21 爱无限 阅读(268) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 3 typedef struct NODE 4 { 5 int data; 6 struct NODE *next; 7 }Node; 8 9 #define N 1010 11 int partition(int a[], int left, int right)12 {13 int low, high;14 int pivot = a[left];15 16 low = left;17 high = right;18 19 while(low < high)20 {21 ... 阅读全文
posted @ 2013-05-12 16:49 爱无限 阅读(153) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 4 typedef struct NODE 5 { 6 int data; 7 struct NODE *next; 8 }Node; 9 10 Node* reverse(Node *head)11 {12 Node *p1, *p2, *p3;13 14 if(head == NULL || head->next == NULL)15 {16 return head;17 }18 19 p1 = head;20 ... 阅读全文
posted @ 2013-05-10 17:27 爱无限 阅读(211) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 #include<string.h> 3 4 #define N 100 5 6 int main() 7 { 8 9 char a[N], b[N];10 int a_real[N], b_real[N], c[N + 1];11 12 int i, j, k = 0;13 int a_len, b_len;14 int max, min;15 int carry_bit = 0, total_bit = 0;16 17 memset(c, 0, sizeof(c));18 m... 阅读全文
posted @ 2013-05-09 19:25 爱无限 阅读(230) 评论(0) 推荐(0)
摘要:摘自《程序员面试宝典》堆和栈的区别一、预备知识—程序的内存分配一个由c/C++编译的程序占用的内存分为以下几个部分1、栈区(stack)—由编译器自动分配释放,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。2、堆区(heap)—一般由程序员分配释放,若程序员不释放,程序结束时可能由OS回收。注意它与数据结构中的堆是两回事,分配方式倒是类似于链表,呵呵。3、全局区(静态区)(static)—,全局变量和静态变量的存储是放在一块的,初始化的全局变量和静态变量在一块区域,未初始化的全局变量和未初始化的静态变量在相邻的另一块区域。-程序结束后有系统释放4、文字常量区—常量字符串就是 阅读全文
posted @ 2011-09-13 09:46 爱无限 阅读(349) 评论(0) 推荐(0)
摘要:#include<stdio.h>int main(){ int c; while((c = getchar()) != EOF) putchar(c); return 0;} 阅读全文
posted @ 2011-06-23 00:13 爱无限 阅读(225) 评论(0) 推荐(0)
摘要:1. printf("%3.0f %6.1f\n",a, b); 右对齐,a 为至少3个数字宽度,且不带小数点和小数部分; b 为至少6个数字宽度,且小数点后面有1位数字。 阅读全文
posted @ 2011-06-22 23:32 爱无限 阅读(178) 评论(0) 推荐(0)
摘要:1. printf 语句永远不会自动换行。 阅读全文
posted @ 2011-06-22 23:28 爱无限 阅读(206) 评论(0) 推荐(0)