正在加载图片...
完整程序1 include <stdio.h> Define ARR SIZE 40 int FindMax( float score囗.intn):/函数声明* void maino /*函数功能: float scory在长度为m的 score数组中找最大值,返回最大值所在的下标*/ n, I, int FindMax(float scoreD], int n) long num[ rinf( plee scanf(%od int i, max i=0: printf("Pled for (i=; i<n; i++) for(i=0; i if (score[i]> score[max_iD Scal max i=Find max I =l rinf("max num[max门] return max i16 完整程序1 #include <stdio.h> #define ARR_SIZE 40 int FindMax(float score[], int n ); /*函数声明*/ void main() { float score[ARR_SIZE], maxScore; int n, i,max_i; long num[ARR_SIZE], maxNum; printf("Please enter total number:"); scanf("%d", &n); /*从键盘输入学生人数n*/ printf("Please enter the number and score:\n"); for (i=0; i<n; i++) /*分别以长整型和实型格式输入学生的学号和成绩*/ { scanf("%ld%f", &num[i], &score[i]); } max_i=FindMax(score, n); /*计算最高分对应的下标*/ printf("maxScore = %.0f, maxNum = %ld\n", score[max_i], num[max_i]); } /*函数功能: 在长度为n的score数组中找最大值,返回最大值所在的下标*/ int FindMax(float score[], int n ) { int i,max_i=0; for (i=1; i<n; i++) { if (score[i] > score[max_i]) { max_i=i; } } return max_i; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有