您的位置:首页 > 其它

利用数组函数进行编写的一个小型学生管理系统。

2018-09-02 15:26 330 查看
[code]#include<stdio.h>
#define N 5
//书写一个小型的学生成绩管理系统
//录入函数
void input(double[]); //1.录入
void sort(double []); //2.排序
void show(double []); //3.打印成绩
int find(double *scores, int findnum);//向传入的数组中查找num,如果存在返回下标,不存在返回-1

int main(){
double findnum;
double scores
;
input (scores);
sort (scores);
show (scores);

printf("请输入要查找的下标:");
scanf("%lf", &findnum);
printf("找到的数字下标为:%d\n",find(scores, findnum) );
return 0;

}

void input(double scores[]){
int i;
for (i = 0; i < N; i++){
printf("请输入第%d门课的成绩:", i + 1);
scanf("%lf", &scores[i]);
}
}

void sort(double scores[]){
int i,j;
int temp;
for(i = 0; i < 	N - 1; i++){
for(j = i + 1; j < N; j++){
if(scores[i] < scores[j]){
temp = scores[i];
scores[i] = scores[j];
scores[j] = temp;
}
}
}

}

void show(double scores[]){
int i;
printf("*******************\n");
printf("语文\t数学\t英语\t物理\t化学\n");
for(i = 0; i < N; i++){
printf("%.lf\t", *(scores + i));
}
printf("\n*******************\n");
}

int find(double * scores, int findnum){
int findindex = -1; //要查找的下标
int i;
for(i = 0; i < N; i++){
//if (findnum == *(scores + i))
if(findnum == scores[i]){
//记录下查找的下标,结束查找动作。
findindex = i;
break;
}
}
return findindex;
}

 

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐