一位数组:
#include <stdio.h>
#include<string.h>
#define N 5
void luru(float s[],int n);
void shuchu(float s[],int n);
void chaxun(float s[],int n);
void paixu(float a[],int n);
int mimayanzheng();
void caidan(); void main(){
int x,y,k;
float a[N];
x=mimayanzheng();
if(x==){
caidan();
for(k=;k!=;k=y){
printf("请输入选择:");
scanf("%d",&y);
switch(y){
case :luru(a,N);break;
case :shuchu(a,N);break;
case :chaxun(a,N);break;
case :paixu(a,N);break;
case :break;
}
}
} }
int mimayanzheng(){
int i,flat;
char m[]="abc123",x[];
printf("请输入密码:");
for(i=;i<;i++){
flat=;
scanf("%s",&x);
if(!strcmp(m,x)){
flat=;
break;
}
else if(i<)
printf("请重新输入密码:");
}
return flat;
} void caidan(){
printf("+===============================+\n");
printf("+====学=生=成=绩=管=理=系=统====+\n");
printf("+===============================+\n");
printf("+===========1、 录入===========+\n");
printf("+===========2、 输出===========+\n");
printf("+===========3、 查询===========+\n");
printf("+===========4、 排序===========+\n");
printf("+===========5、 退出===========+\n");
printf("+===============================+\n");
} void luru(float s[],int n){
int i;
for(i=;i<n;i++){
printf("请输入第%d个同学的成绩:",i+);
scanf("%f",&s[i]);
}
} void shuchu(float s[],int n){
int i;
for(i=;i<n;i++)
printf("第%d个的同学成绩是:%f \n",i+,s[i]);
} void chaxun(float s[],int n){
int i,flat;
float x;
printf("请输入要查询的成绩:");
scanf("%f",&x);
for(i=,flat=;i<n;i++)
if(x==s[i])
flat =;
if(flat==)
for(i=;i<N;i++){
if(s[i]==x)
printf("有此同学成绩,为第%d个同学的成绩\n",i+);
continue;
}
else
printf("没有此同学成绩\n");
} void paixu(float a[],int n){
int i,j,k;
float temp;
for(j=;j<n-;j++){
k=j;
for(i=j+;i<n;i++)
if(a[i]<a[k])
k=i;
if(k!=j){
temp=a[k];
a[k]=a[j];
a[j]=temp;
}
}
printf("从小到大的排序是:");
for(i=;i<N;i++)
printf("%f ",a[i]);
printf("\n");
}
二维数组:
#include <stdio.h>
#include<string.h>
#define a 2
#define b 3 void luru(float s[][b]);
void shuchu(float s[][b]);
void chaxun(float s[][b]);
void paixu(float m[][b]);
int mimayanzheng();
void caidan(); void main(){
int x,y,k;
float z[a][b];
x=mimayanzheng();
if(x==){
caidan();
for(k=;k!=;k=y){
printf("请输入选择:");
scanf("%d",&y);
switch(y){
case :luru(z);break;
case :shuchu(z);break;
case :chaxun(z);break;
case :paixu(z);break;
case :break;
}
}
} }
int mimayanzheng(){
int i,flat;
char m[]="abc123",x[];
printf("请输入密码:");
for(i=;i<;i++){
flat=;
scanf("%s",&x);
if(!strcmp(m,x)){
flat=;
break;
}
else if(i<)
printf("请重新输入密码:");
}
return flat;
} void caidan(){
printf("+===============================+\n");
printf("+====学=生=成=绩=管=理=系=统====+\n");
printf("+===============================+\n");
printf("+===========1、 录入===========+\n");
printf("+===========2、 输出===========+\n");
printf("+===========3、 查询===========+\n");
printf("+===========4、 排序===========+\n");
printf("+===========5、 退出===========+\n");
printf("+===============================+\n");
} void luru(float s[a][b]){
int i,j;
for(j=;j<a;j++){
for(i=;i<b;i++){
printf("请输入第%d个同学的第%d科成绩:",j+,i+);
scanf("%f",&s[j][i]);
}
}
} void shuchu(float s[a][b]){
int i,j;
for(j=;j<a;j++){
for(i=;i<b;i++){
printf("第%d个同学的第%d科成绩是%f:\n",j+,i+,s[j][i]);
}
}
} void chaxun(float s[a][b]){
int i,j,flat;
float x;
printf("请输入要查询的成绩:");
scanf("%f",&x);
for(j=;j<a;j++){
for(i=,flat=;i<b;i++)
if(x==s[j][i])
flat =;
if(flat==){
for(j=;j<a;j++){
for(i=;i<b;i++){
if(s[j][i]==x)
printf("有此同学成绩,为第%d个同学的第%d科成绩\n",j+,i+);
continue;
}
}
}
else
printf("没有此同学成绩\n");
}
} void paixu(float m[a][b]){
int i,j,k,p;
float temp;
for(p=;p<a;p++){
for(j=;j<b-;j++){
k=j;
for(i=j+;i<b;i++)
if(m[p][i]<m[p][k])
k=i;
if(k!=j){
temp=m[p][k];
m[p][k]=m[p][j];
m[p][j]=temp;
}
}
}
printf("从小到大的排序是:\n");
for(j=;j<a;j++){
for(i=;i<b;i++)
printf("%f ",m[j][i]);
printf("\n");
}
printf("\n");
}
指针:
#include <stdio.h>
#include<string.h>
#define N 5
void luru(double *s,int n);
void shuchu(double *s,int n);
void chaxun(double *s,int n);
void paixu(double *a,int n);
int mimayanzheng();
void caidan(); void main(){
int x,y,k;
double b[N];
double *a;
a=b;
x=mimayanzheng();
if(x==){
caidan();
for(k=;k!=;k=y){
printf("请输入选择:");
scanf("%d",&y);
switch(y){
case :luru(a,N);break;
case :shuchu(a,N);break;
case :chaxun(a,N);break;
case :paixu(a,N);break;
case :break;
}
}
} }
int mimayanzheng(){
int i,flat;
char m[]="abc123",x[];
printf("请输入密码:");
for(i=;i<;i++){
flat=;
scanf("%s",&x);
if(!strcmp(m,x)){
flat=;
break;
}
else if(i<)
printf("请重新输入密码:");
}
return flat;
} void caidan(){
printf("+===============================+\n");
printf("+====学=生=成=绩=管=理=系=统====+\n");
printf("+===============================+\n");
printf("+===========1、 录入===========+\n");
printf("+===========2、 输出===========+\n");
printf("+===========3、 查询===========+\n");
printf("+===========4、 排序===========+\n");
printf("+===========5、 退出===========+\n");
printf("+===============================+\n");
} void luru(double * s,int n){
int i;
double k;
for(i=;i<n;i++){
printf("请输入第%d个同学的成绩:",i+);
scanf("%lf",&k);
* (s+i)=k;
}
} void shuchu(double *s,int n){
int i;
for(i=;i<n;i++)
printf("第%d个的同学成绩是:%lf \n",i+,*(s+i));
} void chaxun(double *s,int n){
int i,flat;
double x;
printf("请输入要查询的成绩:");
scanf("%f",&x);
for(i=,flat=;i<n;i++)
if(x==*(s+i))
flat =;
if(flat==)
for(i=;i<n;i++){
if(*(s+i)==x)
printf("有此同学成绩,为第%d个同学的成绩\n",i+);
continue;
}
else
printf("没有此同学成绩\n");
} void paixu(double *a,int n){
int i,j,k;
double temp;
for(j=;j<n-;j++){
k=j;
for(i=j+;i<n;i++)
if(*(a+i)<*(a+k))
k=i;
if(k!=j){
temp=*(a+k);
*(a+k)=*(a+j);
*(a+j)=temp;
}
}
printf("从小到大的排序是:");
for(i=;i<N;i++)
printf("%f ",*(a+i));
printf("\n");
}
结构体:
#include <stdio.h>
#include<string.h>
#define N 5
void luru(struct xitong student[],int n);
void shuchu(struct xitong student[],int n);
void chaxun(struct xitong student[],int n);
void paixu(struct xitong student[],int n);
int mimayanzheng();
void caidan();
struct xitong{
char xingming[];
int xuehao;
float yuwen;
float shuxue;
float yingyu;
}; void main(){
int x,y,k;
struct xitong student [N];
x=mimayanzheng();
if(x==){
caidan();
for(k=;k!=;k=y){
printf("请输入选择:");
scanf("%d",&y);
switch(y){
case :luru(student,N);break;
case :shuchu(student,N);break;
case :chaxun(student,N);break;
//case 4 :paixu(student,N);break;
case :break;
}
}
} }
int mimayanzheng(){
int i,flat;
char m[]="abc123",x[];
printf("请输入密码:");
for(i=;i<;i++){
flat=;
scanf("%s",&x);
if(!strcmp(m,x)){
flat=;
break;
}
else if(i<)
printf("请重新输入密码:");
}
return flat;
} void caidan(){
printf("+===============================+\n");
printf("+====学=生=成=绩=管=理=系=统====+\n");
printf("+===============================+\n");
printf("+===========1、 录入===========+\n");
printf("+===========2、 输出===========+\n");
printf("+===========3、 查询===========+\n");
printf("+===========4、 排序===========+\n");
printf("+===========5、 退出===========+\n");
printf("+===============================+\n");
} void luru(struct xitong student[],int n){
int i;
for(i=;i<n;i++){
printf("请输入第%d个同学的信息(姓名,学号,语文,数学,英语):",i+);
scanf("%s %d %f %f %f",&student[i].xingming,&student[i].xuehao,&student[i].yuwen,&student[i].shuxue,&student[i].yingyu);
}
} void shuchu(struct xitong student[],int n){
int i;
for(i=;i<n;i++)
printf("第%d个的同学信息是: \n姓名:%s\n学号:%d\n语文:%f\n数学:%f\n英语:%f\n",i+,student[i].xingming,student[i].xuehao,student[i].yuwen,student[i].shuxue,student[i].yingyu);
} void chaxun(struct xitong student[],int n){
int i,flat;
float x;
printf("请输入要查询的成绩:");
scanf("%f",&x);
for(i=,flat=;i<n;i++)
if(x==student[i].yuwen||x==student[i].shuxue||x==student[i].yingyu)
flat =;
if(flat==)
for(i=;i<N;i++){
if(x==student[i].yuwen||x==student[i].shuxue||x==student[i].yingyu)
printf("有此同学成绩,为%s同学的成绩\n",student[i].xingming);
continue;
}
else
printf("没有此同学成绩\n");
}