#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[N];
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;
}
利用数组函数进行编写的一个小型学生管理系统。
猜你喜欢
转载自blog.csdn.net/oXunWuQiShi1/article/details/82315856
今日推荐
周排行