一位数组:
1 #include <stdio.h> 2 #include<string.h> 3 #define N 5 4 void luru(float s[],int n); 5 void shuchu(float s[],int n); 6 void chaxun(float s[],int n); 7 void paixu(float a[],int n); 8 int mimayanzheng(); 9 void caidan(); 10 11 12 13 14 15 16 void main(){ 17 int x,y,k; 18 float a[N]; 19 x=mimayanzheng(); 20 if(x==1){ 21 caidan(); 22 for(k=0;k!=5;k=y){ 23 printf("请输入选择:"); 24 scanf("%d",&y); 25 switch(y){ 26 case 1 :luru(a,N);break; 27 case 2 :shuchu(a,N);break; 28 case 3 :chaxun(a,N);break; 29 case 4 :paixu(a,N);break; 30 case 5 :break; 31 } 32 } 33 } 34 35 36 37 } 38 int mimayanzheng(){ 39 int i,flat; 40 char m[7]="abc123",x[10]; 41 printf("请输入密码:"); 42 for(i=0;i<3;i++){ 43 flat=0; 44 scanf("%s",&x); 45 if(!strcmp(m,x)){ 46 flat=1; 47 break; 48 } 49 else if(i<2) 50 printf("请重新输入密码:"); 51 } 52 return flat; 53 } 54 55 void caidan(){ 56 printf("+===============================+ "); 57 printf("+====学=生=成=绩=管=理=系=统====+ "); 58 printf("+===============================+ "); 59 printf("+===========1、 录入===========+ "); 60 printf("+===========2、 输出===========+ "); 61 printf("+===========3、 查询===========+ "); 62 printf("+===========4、 排序===========+ "); 63 printf("+===========5、 退出===========+ "); 64 printf("+===============================+ "); 65 } 66 67 68 void luru(float s[],int n){ 69 int i; 70 for(i=0;i<n;i++){ 71 printf("请输入第%d个同学的成绩:",i+1); 72 scanf("%f",&s[i]); 73 } 74 } 75 76 void shuchu(float s[],int n){ 77 int i; 78 for(i=0;i<n;i++) 79 printf("第%d个的同学成绩是:%f ",i+1,s[i]); 80 } 81 82 void chaxun(float s[],int n){ 83 int i,flat; 84 float x; 85 printf("请输入要查询的成绩:"); 86 scanf("%f",&x); 87 for(i=0,flat=0;i<n;i++) 88 if(x==s[i]) 89 flat =1; 90 if(flat==1) 91 for(i=0;i<N;i++){ 92 if(s[i]==x) 93 printf("有此同学成绩,为第%d个同学的成绩 ",i+1); 94 continue; 95 } 96 else 97 printf("没有此同学成绩 "); 98 } 99 100 void paixu(float a[],int n){ 101 int i,j,k; 102 float temp; 103 for(j=0;j<n-1;j++){ 104 k=j; 105 for(i=j+1;i<n;i++) 106 if(a[i]<a[k]) 107 k=i; 108 if(k!=j){ 109 temp=a[k]; 110 a[k]=a[j]; 111 a[j]=temp; 112 } 113 } 114 printf("从小到大的排序是:"); 115 for(i=0;i<N;i++) 116 printf("%f ",a[i]); 117 printf(" "); 118 } 119
二维数组:
1 #include <stdio.h> 2 #include<string.h> 3 #define a 2 4 #define b 3 5 6 void luru(float s[][b]); 7 void shuchu(float s[][b]); 8 void chaxun(float s[][b]); 9 void paixu(float m[][b]); 10 int mimayanzheng(); 11 void caidan(); 12 13 14 15 16 17 18 void main(){ 19 int x,y,k; 20 float z[a][b]; 21 x=mimayanzheng(); 22 if(x==1){ 23 caidan(); 24 for(k=0;k!=5;k=y){ 25 printf("请输入选择:"); 26 scanf("%d",&y); 27 switch(y){ 28 case 1 :luru(z);break; 29 case 2 :shuchu(z);break; 30 case 3 :chaxun(z);break; 31 case 4 :paixu(z);break; 32 case 5 :break; 33 } 34 } 35 } 36 37 38 39 } 40 int mimayanzheng(){ 41 int i,flat; 42 char m[7]="abc123",x[10]; 43 printf("请输入密码:"); 44 for(i=0;i<3;i++){ 45 flat=0; 46 scanf("%s",&x); 47 if(!strcmp(m,x)){ 48 flat=1; 49 break; 50 } 51 else if(i<2) 52 printf("请重新输入密码:"); 53 } 54 return flat; 55 } 56 57 void caidan(){ 58 printf("+===============================+ "); 59 printf("+====学=生=成=绩=管=理=系=统====+ "); 60 printf("+===============================+ "); 61 printf("+===========1、 录入===========+ "); 62 printf("+===========2、 输出===========+ "); 63 printf("+===========3、 查询===========+ "); 64 printf("+===========4、 排序===========+ "); 65 printf("+===========5、 退出===========+ "); 66 printf("+===============================+ "); 67 } 68 69 70 void luru(float s[a][b]){ 71 int i,j; 72 for(j=0;j<a;j++){ 73 for(i=0;i<b;i++){ 74 printf("请输入第%d个同学的第%d科成绩:",j+1,i+1); 75 scanf("%f",&s[j][i]); 76 } 77 } 78 } 79 80 void shuchu(float s[a][b]){ 81 int i,j; 82 for(j=0;j<a;j++){ 83 for(i=0;i<b;i++){ 84 printf("第%d个同学的第%d科成绩是%f: ",j+1,i+1,s[j][i]); 85 } 86 } 87 } 88 89 void chaxun(float s[a][b]){ 90 int i,j,flat; 91 float x; 92 printf("请输入要查询的成绩:"); 93 scanf("%f",&x); 94 for(j=0;j<a;j++){ 95 for(i=0,flat=0;i<b;i++) 96 if(x==s[j][i]) 97 flat =1; 98 if(flat==1){ 99 for(j=0;j<a;j++){ 100 for(i=0;i<b;i++){ 101 if(s[j][i]==x) 102 printf("有此同学成绩,为第%d个同学的第%d科成绩 ",j+1,i+1); 103 continue; 104 } 105 } 106 } 107 else 108 printf("没有此同学成绩 "); 109 } 110 } 111 112 void paixu(float m[a][b]){ 113 int i,j,k,p; 114 float temp; 115 for(p=0;p<a;p++){ 116 for(j=0;j<b-1;j++){ 117 k=j; 118 for(i=j+1;i<b;i++) 119 if(m[p][i]<m[p][k]) 120 k=i; 121 if(k!=j){ 122 temp=m[p][k]; 123 m[p][k]=m[p][j]; 124 m[p][j]=temp; 125 } 126 } 127 } 128 printf("从小到大的排序是: "); 129 for(j=0;j<a;j++){ 130 for(i=0;i<b;i++) 131 printf("%f ",m[j][i]); 132 printf(" "); 133 } 134 printf(" "); 135 }
指针:
1 #include <stdio.h> 2 #include<string.h> 3 #define N 5 4 void luru(double *s,int n); 5 void shuchu(double *s,int n); 6 void chaxun(double *s,int n); 7 void paixu(double *a,int n); 8 int mimayanzheng(); 9 void caidan(); 10 11 12 13 14 15 16 void main(){ 17 int x,y,k; 18 double b[N]; 19 double *a; 20 a=b; 21 x=mimayanzheng(); 22 if(x==1){ 23 caidan(); 24 for(k=0;k!=5;k=y){ 25 printf("请输入选择:"); 26 scanf("%d",&y); 27 switch(y){ 28 case 1 :luru(a,N);break; 29 case 2 :shuchu(a,N);break; 30 case 3 :chaxun(a,N);break; 31 case 4 :paixu(a,N);break; 32 case 5 :break; 33 } 34 } 35 } 36 37 38 39 } 40 int mimayanzheng(){ 41 int i,flat; 42 char m[7]="abc123",x[10]; 43 printf("请输入密码:"); 44 for(i=0;i<3;i++){ 45 flat=0; 46 scanf("%s",&x); 47 if(!strcmp(m,x)){ 48 flat=1; 49 break; 50 } 51 else if(i<2) 52 printf("请重新输入密码:"); 53 } 54 return flat; 55 } 56 57 void caidan(){ 58 printf("+===============================+ "); 59 printf("+====学=生=成=绩=管=理=系=统====+ "); 60 printf("+===============================+ "); 61 printf("+===========1、 录入===========+ "); 62 printf("+===========2、 输出===========+ "); 63 printf("+===========3、 查询===========+ "); 64 printf("+===========4、 排序===========+ "); 65 printf("+===========5、 退出===========+ "); 66 printf("+===============================+ "); 67 } 68 69 70 void luru(double * s,int n){ 71 int i; 72 double k; 73 for(i=0;i<n;i++){ 74 printf("请输入第%d个同学的成绩:",i+1); 75 scanf("%lf",&k); 76 * (s+i)=k; 77 } 78 } 79 80 void shuchu(double *s,int n){ 81 int i; 82 for(i=0;i<n;i++) 83 printf("第%d个的同学成绩是:%lf ",i+1,*(s+i)); 84 } 85 86 void chaxun(double *s,int n){ 87 int i,flat; 88 double x; 89 printf("请输入要查询的成绩:"); 90 scanf("%f",&x); 91 for(i=0,flat=0;i<n;i++) 92 if(x==*(s+i)) 93 flat =1; 94 if(flat==1) 95 for(i=0;i<n;i++){ 96 if(*(s+i)==x) 97 printf("有此同学成绩,为第%d个同学的成绩 ",i+1); 98 continue; 99 } 100 else 101 printf("没有此同学成绩 "); 102 } 103 104 void paixu(double *a,int n){ 105 int i,j,k; 106 double temp; 107 for(j=0;j<n-1;j++){ 108 k=j; 109 for(i=j+1;i<n;i++) 110 if(*(a+i)<*(a+k)) 111 k=i; 112 if(k!=j){ 113 temp=*(a+k); 114 *(a+k)=*(a+j); 115 *(a+j)=temp; 116 } 117 } 118 printf("从小到大的排序是:"); 119 for(i=0;i<N;i++) 120 printf("%f ",*(a+i)); 121 printf(" "); 122 }
结构体:
1 #include <stdio.h> 2 #include<string.h> 3 #define N 5 4 void luru(struct xitong student[],int n); 5 void shuchu(struct xitong student[],int n); 6 void chaxun(struct xitong student[],int n); 7 void paixu(struct xitong student[],int n); 8 int mimayanzheng(); 9 void caidan(); 10 struct xitong{ 11 char xingming[10]; 12 int xuehao; 13 float yuwen; 14 float shuxue; 15 float yingyu; 16 }; 17 18 19 20 21 22 23 void main(){ 24 int x,y,k; 25 struct xitong student [N]; 26 x=mimayanzheng(); 27 if(x==1){ 28 caidan(); 29 for(k=0;k!=5;k=y){ 30 printf("请输入选择:"); 31 scanf("%d",&y); 32 switch(y){ 33 case 1 :luru(student,N);break; 34 case 2 :shuchu(student,N);break; 35 case 3 :chaxun(student,N);break; 36 //case 4 :paixu(student,N);break; 37 case 5 :break; 38 } 39 } 40 } 41 42 43 44 } 45 int mimayanzheng(){ 46 int i,flat; 47 char m[7]="abc123",x[10]; 48 printf("请输入密码:"); 49 for(i=0;i<3;i++){ 50 flat=0; 51 scanf("%s",&x); 52 if(!strcmp(m,x)){ 53 flat=1; 54 break; 55 } 56 else if(i<2) 57 printf("请重新输入密码:"); 58 } 59 return flat; 60 } 61 62 void caidan(){ 63 printf("+===============================+ "); 64 printf("+====学=生=成=绩=管=理=系=统====+ "); 65 printf("+===============================+ "); 66 printf("+===========1、 录入===========+ "); 67 printf("+===========2、 输出===========+ "); 68 printf("+===========3、 查询===========+ "); 69 printf("+===========4、 排序===========+ "); 70 printf("+===========5、 退出===========+ "); 71 printf("+===============================+ "); 72 } 73 74 75 void luru(struct xitong student[],int n){ 76 int i; 77 for(i=0;i<n;i++){ 78 printf("请输入第%d个同学的信息(姓名,学号,语文,数学,英语):",i+1); 79 scanf("%s %d %f %f %f",&student[i].xingming,&student[i].xuehao,&student[i].yuwen,&student[i].shuxue,&student[i].yingyu); 80 } 81 } 82 83 void shuchu(struct xitong student[],int n){ 84 int i; 85 for(i=0;i<n;i++) 86 printf("第%d个的同学信息是: 姓名:%s 学号:%d 语文:%f 数学:%f 英语:%f ",i+1,student[i].xingming,student[i].xuehao,student[i].yuwen,student[i].shuxue,student[i].yingyu); 87 } 88 89 void chaxun(struct xitong student[],int n){ 90 int i,flat; 91 float x; 92 printf("请输入要查询的成绩:"); 93 scanf("%f",&x); 94 for(i=0,flat=0;i<n;i++) 95 if(x==student[i].yuwen||x==student[i].shuxue||x==student[i].yingyu) 96 flat =1; 97 if(flat==1) 98 for(i=0;i<N;i++){ 99 if(x==student[i].yuwen||x==student[i].shuxue||x==student[i].yingyu) 100 printf("有此同学成绩,为%s同学的成绩 ",student[i].xingming); 101 continue; 102 } 103 else 104 printf("没有此同学成绩 "); 105 }