11 2013 档案
摘要: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(__...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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 ...
阅读全文
摘要: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 ...
阅读全文
摘要: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("请输入学生的学号和成绩,...
阅读全文
摘要: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 ...
阅读全文
摘要: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
阅读全文
摘要: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=
阅读全文
摘要: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 }
阅读全文
摘要:动态申请内存空间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)
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:1 /*被调用函数出现在主调用函数之前*/ 2 #include 3 float cube(float x); 4 int main(void) 5 { 6 float a,product; 7 printf("Please input value of a:\n"); 8 scanf("%f",&a); 9 product=cube(a);10 printf("Cube of %.4f is %.4f\n",a,product);11 return 0;12 }13 float cube(float x)14 {15 flo
阅读全文
摘要:1 /*自定义函数:两数相加*/ 2 #include 3 float add(float x,float y); 4 int main(void) 5 { 6 float i,j,num; 7 printf("please input two numbers:\n"); 8 scanf("%f%f",&i,&j); 9 num=add(i,j);10 printf("The SUM of your inputed is: %.2f\n",num);11 return 0;12 }13 float add(float
阅读全文
摘要:1 /*自定义函数求两个数最大数*/ 2 #include 3 int max(int x,int y); 4 int main(void) 5 { 6 int a,b,c; 7 printf("Please input two integer numbers:\n"); 8 scanf("%d%d",&a,&b); 9 c=max(a,b);10 printf("the largest number is: %d\n",c);11 return 0;12 }13 int max(int x,int y)14 {15
阅读全文
摘要:1 /*交换一组数据的位置*/ 2 #include 3 int main(void) 4 { 5 int a[6],i,j,m,n,temp=0; 6 printf("Please input number:\n"); 7 scanf("%d",&j); 8 printf("Please input %d integer numbers:\n",j); 9 for (i=0;i<j;i++)10 {11 scanf("%d",&a[i]);12 }13 m=j/2;14 for(i=0;i&
阅读全文
摘要:1 /*输出十行杨辉三角形*/ 2 #define N 10 3 #include 4 int main(void) 5 { 6 int s[N][N],i,j; 7 for(i=0;i<=N;i++) 8 { 9 s[i][i]=1;10 s[i][0]=1;11 }12 for(i=2;i<N;i++)13 for(j=1;j<i;j++)14 s[i][j]=s[i-1][j-1]+s[i-1][j];15 for (i=0;i<N;i++)16 { f...
阅读全文
摘要:1 /*三个字符串中找出最大字符串,将最大者输出*/ 2 #include 3 int main(void) 4 { 5 char s[20]; 6 char str1[3][20]; 7 int i; 8 for (i=0;i0)13 strcpy(s,str1[0]);14 else strcpy(s,str1[1]);15 if(strcmp(str1[2],s)>0)16 strcpy(s,str1[2]);17 printf("%s",s);18 return 0;19 }
阅读全文
摘要:1 /*统计字符串中的单词个数*/ 2 #include 3 int main(void) 4 { 5 char a[80]={""},c; 6 int i,num=0,word=0; 7 gets(a); 8 for (i=0;(c=a[i])!='\0';i++) 9 {10 if(c==' ')11 {12 word=0;13 }14 else if(word==0)15 {16 word=1;17 ...
阅读全文
摘要:1 /*用字符数组输出钻石图像*/ 2 #include 3 int main(void) 4 { 5 static char c[][5]={{' ',' ','*'},{' ','*',' ','*'},{'*',' ',' ',' ','*'},\ 6 {' ','*',' ','*'},{' ',' '
阅读全文
摘要:1 /*有一个3X4的矩阵,要求编程序以求出其中值最大的那个数,及其下标*/ 2 #include 3 int main(void) 4 { 5 int i,j,row=0,colum=0,max; 6 int a[3][4]={{1,2,3,4},{9,8,7,6},{-10,10,-5,2}}; 7 max=a[0][0]; 8 for (i=0;imax)12 {13 max=a[i][j];14 row=i;15 colum=j;16...
阅读全文
摘要:1 /*将二行三列数组转换为三行两列数组*/ 2 #include 3 int main(void) 4 { 5 static a[2][3]={{1,2,3},{4,5,6}}; 6 int b[3][2],i,j; 7 printf("array a:\n"); 8 for(i=0;i<2;i++) 9 {10 for (j=0;j<3;j++)11 {12 printf("%5d",a[i][j]);13 b[j][i]=a[i][j];14 }15 ...
阅读全文
摘要:/*输入一组数,用冒泡法排序*/#includeint main(void){int i,j,a[8],k;printf("请输入8个整数:\n");for (i=0;ia[j]){k=a[i];a[i]=a[j];a[j]=k;}}printf("排序后:\n");for(i=0;i<8;i++)printf("%d ",a[i]);putchar('\n');}
阅读全文
摘要:1 /*用数组计算fabonacci数列的前20个数*/ 2 #include 3 int main(void) 4 { 5 static int a[20]={1,1}; 6 int i; 7 for (i=2;i 3 int main(void) 4 { 5 long int f1=1,f2=1; 6 int i=1; 7 for(;i<=20;i++) 8 { 9 printf("%ld\t%ld\t",f1,f2);10 f1=f1+f2;11 f2=f1+f2;12 }1...
阅读全文
摘要:1 /*简单数组*/ 2 #include 3 int main(void) 4 { 5 int i,a[10]; 6 for(i=0;i=0;i--) 9 printf("a[%d]=%d ",i,a[i]);10 putchar('\n');11 }
阅读全文
摘要:1 /*输出以下图案*/ 2 /* 3 # # # # # 4 # # # # # 5 # # # # # 6 # # # # # 7 */ 8 #include 9 int main(void)10 {11 char a='#';12 char s=' ';13 int i,j;14 for (i=0;i<5;i++)15 {16 for (j=0;j<=i;j++)17 18 printf("%c",s);19 20 for(j=0;j<5;j++)21...
阅读全文
摘要:1 /*统计行中的单词个数*/ 2 #include 3 int main(void) 4 { 5 char string[81],c; 6 int i,num=0,word=0; 7 gets(string); 8 for(i=0;(c=string[i])!='\0';i++) 9 {10 if(c==' ')11 { word=0;}12 else if(word==0)13 { word=1;14 num++;}15 }16 printf...
阅读全文
摘要:1 /*输出水仙花数*/ 2 #include 3 int main(void) 4 { 5 int i,j,k,l,m; 6 printf("The Narcissus is: "); 7 for(i=100;i 3 int main(void) 4 { 5 int i,j,k,l; 6 printf("The Narcissus is: "); 7 for(i=1;i<=9;i++) 8 for(j=0;j<=9;j++) 9 for(k=0;k<=9;k++)10 {11 ...
阅读全文
摘要:1 /*九九乘法表*/ 2 #include 3 int main(void) 4 { 5 int i,j; 6 for(i=1;i 3 int main(void) 4 { 5 int i,j; 6 for(i=1;i<=9;i++) 7 { 8 printf("%4d",i); 9 }10 printf("\n");11 printf("-------------------------------------\n");12 13 for(i=1;i<=9;i++)14 {15 ...
阅读全文
摘要:1 /*加密算法:如果输入的是字母,将其转换为其后第四位字母*/ 2 #include 3 int main(void) 4 { 5 char c; 6 while((c=getchar())!='\n') 7 { 8 if(c>'A'&&c'a'&&c'Z'&&c'z')12 c=c-26;13 }14 printf("%c",c);15 }16 printf("\n");17 return 0;18 }
阅读全文
摘要:1 /*求100~200之间的素数,每行输出10个素数*/ 2 #include 3 #include 4 int main(void) 5 { 6 int n,k,i,m=0; 7 for(n=101;n<=200;n+=2) 8 { 9 k=sqrt(n);10 for(i=2;i<=k;i++)11 {12 if(n%i==0)13 break;14 if(i==k)15 {16 printf("%d ...
阅读全文
浙公网安备 33010602011771号