随笔分类 -  C语言程序设计

摘要:1 #include 2 #define WrdIn 1 3 #define WrdOut 0 4 main() 5 { 6 int c,nl,nw,nc,state; 7 state=WrdOut; 8 nl=nw=nc=0; 9 while ( (c=getchar()) !=EOF)10 {11 ++nc;12 if(c=='\n')13 ++nl;14 if(c==' ' || c=='\n' || c== '\t')15 state = WrdOu... 阅读全文
posted @ 2014-01-04 00:52 ASMLearner 阅读(196) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 int main(void) 4 { 5 int i; 6 for(i=1;i<=20;i++) 7 { 8 printf("%10d",1+rand()%6); 9 if(i%5==0)10 {11 printf("\n");12 }13 }14 } 阅读全文
posted @ 2013-12-30 22:42 ASMLearner 阅读(327) 评论(0) 推荐(0)
摘要:1 #include 2 int main(void) 3 { 4 float x,y,z; 5 printf("Please input the x,y,z: "); 6 scanf("%f%f%f",&x,&y,&z); 7 if ((x+y)>z && (x+z)>y && (y+z)>x ) 8 printf("YES"); 9 else 10 printf("NO!");11 return 0;12 } 阅读全文
posted @ 2013-12-06 16:27 ASMLearner 阅读(292) 评论(0) 推荐(0)
摘要:1 #include 2 int main(void) 3 { 4 int x,i,j; 5 printf("Please input the length(1-20): \n"); 6 scanf("%d",&x); 7 for (i=1;i<=x;i++) 8 printf("* "); 9 printf("\n");10 for (i=1;i<=x-2;i++)11 {12 printf("* ");13 for (j=1;j<=x-2;j++)14 {15 .. 阅读全文
posted @ 2013-12-06 00:26 ASMLearner 阅读(342) 评论(0) 推荐(0)
摘要:格式如下:N 10*N 100*N 1000*N1 10 100 10002 20 200 2000...............................................10 100 1000 10000 1 #include 2 int main(void) 3 { 4 int n=1; 5 printf("N 10*N 199*N 1000*N\n\n"); 6 while(n<=10) 7 { 8 printf("%d\t%d\t%d\t%d\t\n",n,n*1... 阅读全文
posted @ 2013-12-05 23:06 ASMLearner 阅读(355) 评论(0) 推荐(0)
摘要:要求:使用到变量:counter:一个计数量为10的计数器(例如,记录已经输入了多少个数并确定何时所有10个数都已经比较处理过. number: 当前输入数. largest:当前最大数.initialize largest to zerolnitialize counter to oneInput the first numberwhile counter less thanor equal to ten set largest to number Input the next number if largest less than number setlargest to nu... 阅读全文
posted @ 2013-12-05 22:55 ASMLearner 阅读(595) 评论(0) 推荐(0)
摘要:1 #include 2 int main(void) 3 { 4 float gallons=0,miles,TotGallons=0,TotMiles=0; 5 while (gallons!=-1) 6 { 7 printf("Enter the gallons used (-1 to end):"); 8 scanf("%f",&gallons); 9 10 if(gallons!=-1)11 {12 printf("Enter the miles driven:");13... 阅读全文
posted @ 2013-12-05 16:48 ASMLearner 阅读(894) 评论(0) 推荐(0)
摘要:1 #if __STDC__ 2 #define _Cdecl 3 #else 4 #define _Cdecl cdecl 5 #endif 6 7 #if !defined(__STDIO_DEF_) 8 #define __STDIO_DEF_ 9 10 #ifndef _SIZE_T 11 #define _SIZE_T 12 typedef unsigned size_t; 13 #endif 14 #ifndef NULL 15 # if defined(__TINY__) || defined(__SMALL__) || defined(__... 阅读全文
posted @ 2013-11-25 23:32 ASMLearner 阅读(410) 评论(0) 推荐(0)
摘要:1 /*编写一个学生成绩输出程序,要求:编写一个函数print,打印一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括 2 num,name,score[3],主函数已有这些记录,用print函数输出这些记录。 3 */ 4 #include 5 void print(struct Student *p ); 6 struct Student 7 { 8 int num; 9 char name[20];10 float score[3];11 };12 int main(void)13 {14 struct Student stu[5]={101... 阅读全文
posted @ 2013-11-24 01:43 ASMLearner 阅读(808) 评论(0) 推荐(0)
摘要:1、先用定义变量的方法给出定义体。2、将变量名换为新类型名。3、再用typedef定义新类型名。4、用新类型名去定义新变量。例:1、int a[10]; 2、int array[10]; 3、typedef int array[10]; 4、array n1;定义新结构体:1、先定义结构体struct date{ int year;int month;int day}d;2、定义新的结构变量struct date{ int year;int month;int day}DATE;3、typedef定义新的结构类型typedef struct date{ int year;int mont... 阅读全文
posted @ 2013-11-24 00:29 ASMLearner 阅读(956) 评论(0) 推荐(0)
摘要:1 #include 2 int main(void) 3 { 4 enum Color {red,yellow,blue,white,black}; 5 int i,j,k; 6 int n=0,pri,loop; 7 for (i=red;i<=black;i++) 8 { 9 for (j=red;j<=black;j++)10 {11 if(i!=j)12 {13 for(k=red;k<=black;k++)14 ... 阅读全文
posted @ 2013-11-24 00:12 ASMLearner 阅读(5691) 评论(0) 推荐(0)
摘要:1 /*动态链表的建立与输出*/ 2 #include 3 #include 4 #define N sizeof(struct Student) 5 struct Student 6 { 7 int num; 8 float score; 9 struct Student *next;10 };11 void print(struct Student *head);12 struct Student *creat(void);13 int main(void)14 {15 struct Student *pt;16 pt=creat();17 ... 阅读全文
posted @ 2013-11-22 00:16 ASMLearner 阅读(461) 评论(0) 推荐(0)
摘要:1 #include 2 #define LEN sizeof(struct Student) 3 struct Student 4 { 5 int num; 6 float score; 7 struct Student *next; 8 }; 9 int n=0;10 struct Student *creat()11 {12 struct Student *p1,*p2,*head;13 p1=p2=(struct Student *)malloc(LEN);14 head=NULL;15 printf("请输入学生的学号和成绩,... 阅读全文
posted @ 2013-11-21 23:36 ASMLearner 阅读(282) 评论(0) 推荐(0)
摘要:1 #include 2 struct Student 3 { 4 int num; 5 float score; 6 struct Student *next; 7 }; 8 int main() 9 {10 struct Student a,b,c,*head,*p;11 a.num=10101;a.score=89.5;12 b.num=10103;b.score=90;13 c.num=10107;c.score=85;14 head=&a;15 a.next=&b;16 b.next=&c;17 ... 阅读全文
posted @ 2013-11-21 20:46 ASMLearner 阅读(264) 评论(0) 推荐(0)
摘要:1 /*有n个学生的信息(包括学号、姓名、成绩),要求按照成绩的高低顺序输出各学生的信息。*/ 2 #include 3 struct student 4 { 5 int number; 6 char name[20]; 7 int score; 8 }; 9 int main(void)10 { struct student stu[5]={001,"wang",80,002,"zhang",89,003,"wang",60,004,"zhao",97,005,"sun",100};11 st 阅读全文
posted @ 2013-11-21 01:45 ASMLearner 阅读(5557) 评论(0) 推荐(0)
摘要:1 #include 2 struct leader 3 { 4 char name[20]; 5 int count; 6 }lead[]={"li",0,"wang",0,"zhao",0}; 7 void main(void) 8 { 9 int i,j; char lead1[20];10 printf("Please input the name with \"li\" and \"wang\" or \"zhao\"\n");11 for(i= 阅读全文
posted @ 2013-11-21 00:25 ASMLearner 阅读(453) 评论(0) 推荐(0)
摘要:1 /*动态定义数组*/ 2 #include 3 #include 4 void main() 5 { 6 int i,n,*p; 7 printf("Please input n:\n"); 8 scanf("%d",&n); 9 p=(int *)malloc(n*sizeof(int));10 for(i=0;i<n;i++)11 p[i]=i*i;12 for(i=0;i<n;i++)13 printf("n=%d\t",p[i]);14 free(p);15 return 0;16 } 阅读全文
posted @ 2013-11-18 00:03 ASMLearner 阅读(207) 评论(0) 推荐(0)
摘要:动态申请内存空间void malloc(unsigned int n),申请成功则返回空间首地址,反之返回NULL值;void calloc(unsigned int n,int size) 动态申请N个长度为size 的空间; void realloc(void *p,unsigned int size) 改变动态空间大小;释放空间函数free(void *p) 阅读全文
posted @ 2013-11-17 23:45 ASMLearner 阅读(198) 评论(0) 推荐(0)
摘要:1 /*函数的递归调用*/ 2 #include 3 int age(int n); 4 int main(void) 5 { 6 printf("%d\n",age(5)); 7 return 0; 8 } 9 int age(int n)10 {11 int r;12 if(n==1)13 {14 return 10;15 }16 else 17 {18 r=age(n-1) + 2;19 }20 return (r);21 }22 阅读全文
posted @ 2013-11-07 22:09 ASMLearner 阅读(875) 评论(0) 推荐(0)
摘要:1 /*函数嵌套调用*/ 2 #include 3 float dif(float x,float y,float z); 4 float max(float x,float y,float z); 5 float min(float x,float y,float z); 6 int main(void) 7 { 8 float a,b,c,r; 9 printf("Please input three numbers:\n");10 scanf("%f%f%f",&a,&b,&c);11 r=max(a,b,c);12 pri 阅读全文
posted @ 2013-11-07 21:22 ASMLearner 阅读(545) 评论(0) 推荐(0)