LRS言叶
2019-03-06 15:59
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 10
int main()
{
int score[N] = {67,98,75,63,82,79,81,91,66,84};
float sum, max_score, min_score, avg;
int i, j, temp;
//计算考试总分
for(i = 0; i < N; i++)
{
sum += score[i];
}
printf("考试总分为:%.2f\n",sum);
printf("*********************************\n");
//计算考试平均分
avg = sum / N;
printf("考试平均分为:%.2f\n",avg);
printf("*********************************\n");
//考试成绩降序排序
for(i = N - 1; i > 0; i--)
{
for(j = 0; j <= i; j++)
{
if(score[j] < score[j+1])
{
temp = score[j];
score[j] = score[j+1];
score[j+1] = temp;
}
}
}
for(i = 0; i < N; i++)
{
printf("%d\t",score[i]);
}
printf("\n");
printf("*********************************\n");
//查询最高分
max_score = 0;
for(i = 0; i < N; i++)
{
if(score[i] > max_score)
{
max_score = score[i];
}
}
printf("最高分为:%.2f\n",max_score);
printf("*********************************\n");
//查询最低分
min_score = 100;
for(i = 0; i < N; i++)
{
if(score[i] < min_score)
{
min_score = score[i];
}
}
printf("最高分为:%.2f\n",min_score);
printf("*********************************\n");
return 0;
}
总分:786.00
平均分:78.60
降序排列:98 91 84 82 81 79 75 66 63
最高:98.00
最低:63.00(目前还不会用函数)
#include <stdio.h>
# define N 10
int sum(int score[])
{
int i,sum=0;
for(i=0;i<10;i++)
{
sum+=score[i];
}
return sum;
}
int high(int score[])
{
int i,high=score[0];
for(i=0;i<10;i++)
{
if(score[i]>high)
high=score[i];
}
return high;
}
int low( int score[])
{
int i,low=score[0];
for(i=0;i<10;i++)
{
if(score[i]<low)
low=score[i];
}
return low;
}
float ave(int score[])
{
float ave=(float)(sum(score))/N;
return ave;
}
void xu(int score[])
{
int i,j;
for(i=8;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if(score[j]>score[j+1])
{
int temp;
temp=score[j];
score[j]=score[j+1];
score[j+1]=temp;
}
}
}
printf("降序为");
for(i=0;i<10;i++)
{
if(i==9)
printf("%d\n",score[i]);
else
printf("%d,",score[i]);
}
}
int main()
{
int score[N]={67,98,75,63,82,79,81,91,66,84};
printf("总分为%d\n",sum(score));
printf("最高分为%d\n",high(score));
printf("最低分为%d\n",low(score));
printf("平均分为%f\n",ave(score));
xu(score);
return 0;
}
有大佬瞅瞅有什么不规范还可以改的咩。。。。。 (小声说)
C语言入门
926207 学习 · 20797 问题
相似问题