书写一个小型的学生成绩管理系统
1 //书写一个小型的学生成绩管理系统 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 #define N 5 6 //书写一个小型的学生成绩管理系统 7 void input(double []); 8 void sort(double []); 9 void show(double []); 10 //向传入数组中查找num,如果存在,返回下标,不存在,返回-1 11 int find(double *,int ); 12 13 14 int main() 15 { 16 17 //量数组的大小 18 double test[] = {1,2,3,4,88,66,77,88,66}; 19 printf("test数组的元素个数:%d\n",sizeof(test) / sizeof(test[0])); 20 //sizef(test) 是test空间里的所有元素占的 空间 double类型 是 8 个字节 一共9 个 就是72 21 //sizeof(test[0]) 是 量第一个元素所占的 空间 ==》72 /8 = 9 9个元素 22 23 24 25 double scores[N]; 26 double findNum; //要查找的数字 27 //1.录入 28 input(scores); 29 printf("排序前:\n"); 30 show(scores); 31 32 //2.排序 33 sort(scores); 34 35 //3.打印 36 printf("排序后:\n"); 37 show(scores); 38 //4.一共几个元素 39 printf("scores数组的元素个数:%d\n",sizeof(scores) / sizeof(scores[0])); 40 //5.查找 41 printf("请输入要查找的数字:"); 42 scanf("%lf",&findNum); 43 printf("找到的数字下标为:%d\n",find(scores,findNum)); 44 return 0; 45 } 46 47 48 //查找 49 int find(double * scores,int findNum ) 50 { 51 int findIndex = -1; //要查找的下标 52 int i; 53 for(i = 0; i <N ;i++) 54 { 55 //if(findNum ==*(scores + i)) 56 if(findNum ==scores[i]) 57 { 58 //记录下要查找的下标,结束查找 59 findIndex = i; 60 break; 61 } 62 } 63 64 return findIndex; 65 } 66 67 //录入 68 void input(double * scores) 69 { 70 int i ; 71 for (i =0; i <N; i++) 72 { 73 printf("请输入第%d门课的成绩:",i + 1); 74 // scanf("%lf",&scores[i]); 75 scanf("%lf",(scores + i)); 76 } 77 } 78 79 80 //排序 81 void sort(double scores[]) 82 { 83 int i,j; 84 double temp; 85 for(i = 0;i < N - 1;i++ ) 86 { 87 for(j = 0; j< N - i- 1;j++) 88 { 89 if(scores[j] < scores[j+1]) 90 { 91 temp = scores[j]; 92 scores[j] = scores[j+1]; 93 scores[j+1] = temp; 94 } 95 } 96 97 } 98 99 100 } 101 //展示 102 void show(double scores[]) 103 { 104 int i; 105 printf("******************************************\n"); 106 printf("语文\t数学\t英语\t物理\t化学\n"); 107 108 for(i = 0; i<N ;i++) 109 { 110 printf("%.2lf\t",*(scores + i)); 111 } 112 printf("\n******************************************\n"); 113 114 }

本文来自博客园,作者:Bytezero!,转载请注明原文链接:https://www.cnblogs.com/Bytezero/p/15072371.html
浙公网安备 33010602011771号