Chalice
2017-05-23 17:51
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" int sumScore(int score[],int arrLen) { int sumS = 0; for (int i = 0; i <arrLen;i++) { sumS += score[i]; } ; return sumS; } int maxScore(int score[], int arrLen) { int maxScore = 0; for (int i = 0; i < arrLen - 1; i++) { if (score[i] > score[i + 1]) { int temp = score[i]; score[i] = score[i + 1]; score[i + 1] = temp; maxScore = score[arrLen - 1]; } } printf("考试的最高分为:%d \n", maxScore); return 0; } int mixScore(int score[], int arrLen) { int mixScore = 0; for (int i = 0; i < arrLen-1; i++) { if (score[i] < score[i + 1]) { int temp = score[i]; score[i] = score[i + 1]; score[i + 1] = temp; mixScore = score[arrLen - 1]; } } printf("考试的最低分为:%d \n",mixScore); return 0; } float averageScore(int score[], float arrLen, float sumS) { float averageS; averageS = sumS / arrLen; printf("考试的平均分为:%.1f \n", averageS); return 0; } int dSortScore(int score[], int arrLen) { for (int i = 0; i < arrLen; i++) //降序排列 { for (int j = 0; j < arrLen -1; j++) { if (score[i] > score[j]) { int temp = score[i]; score[i] = score[j]; score[j] = temp; } } } printf("考试成绩降序排序如下: \n"); for (int k = 0; k < arrLen; k++) { printf("%d \n", score[k]); } return 0; } int main() { int score[] = { 67,98,75,63,82,79,81,91,66,84 }; int arrLen = sizeof(score) / sizeof(int); printf("考试的总分为:%d \n", sumScore(score, arrLen));//没直接在函数里写死输出是为了方便平均数函数的调用。 maxScore(score, arrLen); mixScore(score, arrLen); averageScore(score,arrLen, sumScore(score, arrLen)); dSortScore(score, arrLen); getchar(); return 0; }
这是我写的,你看看,结果都一样,过程不一样,也帮忙看看我这个有没有要改进的!
#include"stdio.h"
#include"string.h"
#include"conio.h"
#include"windows.h"
#define N 10
int main()
{
int score[N]={67,98,75,63,82,79,81,91,66,84};
int totalpoints=0;//总分
int max;//最大值
int min;//最小值
int avg;//平均分
int i,j,t;//降序
//总分
for ( i = 0; i < N; i ++ )
{
totalpoints+=score[i];
}
printf("\n 总分=%d \n\n",totalpoints);
//最大值 最小值
max=score[0];//把数组的第一个值赋给最大值
min=score[0];//把数组的第一个值赋给最小值
for ( i = 0; i < N; i ++ )
{
if ( score[i] > max )
{
max=score[i];
}
if ( score[i] < min )
{
min=score[i];
}
}
printf("\n max=%d \t min=%d \n\n",max,min);
//平均值
avg=totalpoints/10;
printf("\n 平均值=%d \n\n",avg);
//降序
printf("\n排序之前输出: \n");
for ( i = 0; i < 10; i ++ )
{
printf("%d\t",score[i]);
}
printf("\n");
for ( j = 0; j < 9; j ++ )
{
for ( i = 0; i < 9-j; i ++ )
{
if ( score[i] < score[i+1] )
{
t = score[i];
score[i] = score[i+1];
score[i+1] = t;
}
}
}
printf("排序之前输出: \n");
for ( i = 0; i < 10; i ++ )
{
printf("%d \t",score[i]);
}
printf("\n\n");
return 0;
}
C语言入门
926289 学习 · 20799 问题
相似问题