10 2013 档案

摘要:1 STU *invert(STU *head){ 2 STU *new_head=NULL,*p1,*p2,*new; 3 do{ 4 for(p1=head;p1->next!=NULL;p1=p1->next) 5 p2=p1; 6 if(new_head==NULL) 7 { 8 new_head=p1; 9 new_head->next=p2;10 }11 else12 {13 ... 阅读全文
posted @ 2013-10-27 18:01 Andy Cheung 阅读(3030) 评论(0) 推荐(0)
摘要:1.我的思路先将b链表连接在a链表的后面,这个很容易实现,将a链表最后的结点中的p.next改为指向b链表的头结点即可。再将这个新链表用选择排序即可。代码如下: 1 #include 2 #include 3 #include 4 5 typedef struct student{ 6 int num; 7 float score; 8 struct student *next; 9 } STU;10 11 int main(){12 setbuf(stdout,NULL);13 STU *creat();14 void print(STU *... 阅读全文
posted @ 2013-10-26 20:11 Andy Cheung 阅读(3189) 评论(0) 推荐(0)
摘要:1.先贴我自己的代码 1 #include 2 #include 3 4 int main(){ 5 setbuf(stdout,NULL); 6 typedef struct{ 7 int year; 8 int month; 9 int day;10 } DATE;11 int num=0;12 int tue;13 DATE date;14 15 printf("Input the date:\n");16 scanf("%d/%d/%d",&date.year,&date.... 阅读全文
posted @ 2013-10-26 16:41 Andy Cheung 阅读(946) 评论(0) 推荐(0)
摘要:假设int型用两个字节表示对于有符号的整数,用补码表示的话,最高位是符号位,后面15位用来表示数据.1.正数,表示的范围为0000 0000 0000 0001-0111 1111 1111 1111,最高位是符号位,不能用于表示数据,所以正数的数值范围为1~32767.2.0:0000 0000 ... 阅读全文
posted @ 2013-10-26 11:18 Andy Cheung 阅读(2104) 评论(0) 推荐(0)
摘要:这是谭浩强课本上枚举类型的例子,但是我贴这个例子的代码不是因为枚举类型,是因为这个代码使用switch语句用得非常好,值得一贴。题目是这样的:有红、黄、蓝、白、黑5中颜色的球若干,依次取出3个球,求3个球为不同颜色时的排列方式。 1 #include 2 3 int main(){ 4 enum color {red,yellow,blue,white,black}; 5 enum color i,j,k,pri; 6 int n=0,loop; 7 for(i=red;i<=black;i++) 8 for(j=red;j<=black;j+... 阅读全文
posted @ 2013-10-25 22:09 Andy Cheung 阅读(352) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 5 #define LEN sizeof(struct student) 6 7 struct student{ 8 long num; 9 float score; 10 stru... 阅读全文
posted @ 2013-10-25 17:02 Andy Cheung 阅读(292) 评论(0) 推荐(0)
摘要:1.新建算法:使p1指向新开辟的结点,p2指向链表中最后一个结点,把p1所指的结点连接在p2所指结点的后面,用“p2->next=p1”来实现。 1 #include 2 #include 3 #include 4 5 #define LEN sizeof(struct student) 6 7... 阅读全文
posted @ 2013-10-23 16:49 Andy Cheung 阅读(474) 评论(1) 推荐(0)
摘要:例子:从键盘输入若干行字符(每行长度不等),输入后把它们存储到一磁盘文件中。再从该文件中读入这些数据,将其中小写字母转换成大写字母后再显示屏上输出。有两种方法1.使用feof()函数 1 #include 2 #include 3 #include 4 5 int main(){ 6 se... 阅读全文
posted @ 2013-10-22 10:23 Andy Cheung 阅读(4055) 评论(0) 推荐(0)
摘要:使用书上的一个课后题为例有5个学生,每个学生有3门课的成绩,从键盘输入学生数据(包括学号,姓名,3们课程成绩),计算出每个学生的平均成绩,将原有数据和计算出的平均分数存放在磁盘文件“stud”中。屡次调试后,我编好的程序: 1 #include 2 #include 3 #define FWRITE... 阅读全文
posted @ 2013-10-21 10:54 Andy Cheung 阅读(3220) 评论(3) 推荐(0)
摘要:课本上时这样写的:(用putchar(ch);代表对取出来的字符的处理。)1 while(!feof(fp))2 {3 ch=fgetc(fp);4 putchar(ch);5 }但是,这样写的话,fgetc()函数总是会多读入一个字符。应该改为如下形式:1 ch=fgetc(fp)... 阅读全文
posted @ 2013-10-20 21:24 Andy Cheung 阅读(2048) 评论(2) 推荐(0)
摘要:1 #include 2 #include 3 4 int main(){ 5 setbuf(stdout,NULL); 6 int move(int,int); 7 int value,n; 8 int result; 9 10 printf("Input the value:\n");11 scanf("%x",&value);12 13 printf("How to move?\n");14 scanf("%d",&n);15 16 result=move(value,n);17 printf 阅读全文
posted @ 2013-10-18 21:41 Andy Cheung 阅读(1662) 评论(0) 推荐(0)
摘要:1.先贴我的代码,VC6.0开发环境下去掉第5行。 1 #include 2 #include 3 4 int main(){ 5 setvbuf(stdout,NULL,_IONBF,0); 6 int value; 7 int getodds(int value); 8 9 printf("Input the value:");10 scanf("%o",&value);11 12 printf("The result is %o.",getodds(value));13 14 return EXIT_SUCCESS;15 阅读全文
posted @ 2013-10-18 17:35 Andy Cheung 阅读(5571) 评论(0) 推荐(0)
摘要:1.选择合适的算法和数据结构应该熟悉算法语言,知道各种算法的优缺点,具体资料请参见相应的参考资料,有很多计算机书籍上都有介绍。将比较慢的顺序查找法用较快的二分查找或乱序查找法代替,插入排序或冒泡排序法用快速排序、合并排序或根排序代替,都可以大大提高程序执行的效率。选择一种合适的数据结构也很重要,比如... 阅读全文
posted @ 2013-10-17 10:20 Andy Cheung 阅读(1629) 评论(0) 推荐(0)
摘要:这是嵌入式C程序员的基本知识。作者在Embedded Systems Programming杂志上发表了很多嵌入式系统开发方面的文章。 C语言测试是招聘嵌入式系统程序员过程中必须而且有效的方法。这些年,我既参加也组织了许多这种测试,在这过程中我意识到这些测试能为面试者和被面试者提供许多有用信息,此... 阅读全文
posted @ 2013-10-17 10:02 Andy Cheung 阅读(323) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 4 int main(){ 5 setvbuf(stdout,NULL,_IONBF,0); 6 char s1[255],s2[255]; 7 int strcmp(char *,char *); 8 int result; 9 10 printf("1st string:");11 gets(s1);12 printf("2nd string:");13 gets(s2);14 result=strcmp(s1,s2);15 printf("The compa... 阅读全文
posted @ 2013-10-16 11:21 Andy Cheung 阅读(3878) 评论(0) 推荐(0)
摘要:#include#include#include#includeint main(){ setvbuf(stdout,NULL,_IONBF,0); char s[255]; int a[255]; //存放得到的整数 int i,length; ... 阅读全文
posted @ 2013-10-16 09:41 Andy Cheung 阅读(7380) 评论(0) 推荐(0)
摘要:#include#includeint main(){ setvbuf(stdout,NULL,_IONBF,0); int a[5][5]; int i,j; void process(int *a); printf("Input the matrix:\n"); for(i=0;ia[max]) max=i; if(max!=12) { t=a[max]; a[max]=a[12]; a[12]=t; } //寻找4个小数,放四角 for(i=0;i<4;i++... 阅读全文
posted @ 2013-10-14 16:35 Andy Cheung 阅读(3210) 评论(0) 推荐(0)
摘要:先写我的思路,没有用指针的做法。如果你用的是VC,把第六行去掉。#include#includeint main(){ setvbuf(stdout,NULL,_IONBF,0); int n,num; //n为总人数,num为剩余人数。 int a[255... 阅读全文
posted @ 2013-10-12 17:41 Andy Cheung 阅读(5550) 评论(1) 推荐(1)
摘要:#include#includevoid double_(int n){ int *p,*q,i=1,j,s,jw=0; p=(int *)malloc(sizeof(int)); *p=1; for(j=1;j=10) { *(p+s)=(*(p+s))*2+jw-10; jw=1; } else { *(p+s)=(*(p+s))*2+jw; jw=0; ... 阅读全文
posted @ 2013-10-11 20:29 Andy Cheung 阅读(1220) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 4 int main() 5 { 6 setvbuf(stdout,NULL,_IONBF,0); //使用Eclipse开发环境时必须写。 7 void process(int *,int,int); 8 int a[255]; 9 int n,m;10 int i;11 12 printf("How many numbers?");13 scanf("%d",&n);14 printf("Input n numbers:");15 for(i=0;i 2 #inc... 阅读全文
posted @ 2013-10-11 18:30 Andy Cheung 阅读(2677) 评论(0) 推荐(0)