《03 00 C语言 全59讲 主讲-苏小红 哈尔滨工业大学》百度网盘资源免费下载
链接: https://pan.baidu.com/s/1YAxqTBta2f0LJoGW2eytGw
?pwd=riuy 提取码: riuy03 00 C语言 全59讲 主讲-苏小红 哈尔滨工业大学|各学科 学习视频目录|1-30讲|课程目录.txt|C语言哈工大教材 苏小红.jpg|9.flv|8.flv|7.flv|6.flv|5.flv|4.flv|30.flv|3.flv|29.flv|28.flv
#include <stdio.h>#define N 30
int Average(int score[], int n)/* Average()函数原型 */
void ReadScore(int score[], long num[],int n)/* ReadScore()函数原型 */
void DataSort(int score[], long num[], int n)
void PrintScore(int score[], long num[], int n)
void DataNum(int score[], long num[], int n)
void PrintNum(int score[], long num[], int n)
void SearchNum(int score[],long num[],int n)
void Statistics(int score[], int n)
void List(int score[], long num[], int n)
int main()
{
int choice,n,score[N], aver=0,i,sum=0
long num[N]
do
{
printf("1: Append record\n")
printf("2: Caculate total and average score of course\n")
printf("3: Sort in descending order by score\n")
printf("4: Sort in ascending order by number\n")
printf("5: Search by number\n")
printf("6: Statistic analysisc\n")
printf("7: List record\n")
printf("0: Exit\n")
scanf("%d",&choice)
switch(choice)
{
case 1:printf("Total students are:")
scanf("%d",&n)
ReadScore (score,num,n)
break
case 2:aver = Average(score, n)
printf("Average score is %d\n",aver)
for (i=0i<ni++)
{
sum += score[i]
}
printf("Caculate total score is %d\n",sum)
break
case 3:DataSort(score,num,n)
printf("Sorted scores :\n")
printf(" number:score: \n")
PrintScore(score,num,n)
break
case 4:DataNum(score,num,n)
printf("Sorted number :\n")
printf(" number:score: \n")
PrintNum(score,num,n)
break
case 5:SearchNum(score,num,n)
break
case 6:Statistics(score, n)
break
case 7:List(score,num,n)
break
case 0:break
}
}while(choice!=0)
return 0
}
void ReadScore(int score[], long num[],int n)
{
int i
for(i=0i<ni++)
{
printf("Input student's ID and score:")
scanf("%ld%d",&num[i],&score[i])
}
}
/* 2、函数功能:计算课程的总分和平均分 */
int Average(int score[], int n) /* Average()函数定义 */
{
int i, sum = 0
for (i=0i<ni++)
{
sum += score[i]
}
return sum / n
}
/* 3、函数功能:成绩由高到低排序 */
void DataNum(int score[], long num[], int n)
{
int i,j,k,temp1
long temp2
for(i=0i<n-1i++)
{
k=i
for(j=i+1j<nj++)
{
if (score[j]>score[k])
{
k=j
}
}
if(k!=i)
{
temp1=score[k]score[k]=score[i]score[i]=temp1
temp2=num[k]num[k]=num[i]num[i]=temp2
}
}
}
/* 函数功能:显示排序后学生学号和成绩 */
void PrintNum(int score[], long num[], int n)
{
int i
for(i=0i<ni++)
{
printf(" %10ld%4d\n",num[i],score[i])
}
}
/* 4、函数功能:学号由小到大排序 */
void DataSort(int score[], long num[], int n)
{
int i,j,k,temp1
long temp2
for(i=0i<n-1i++)
{
k=i
for(j=i+1j<nj++)
{
if (num[j]<num[k])
{
k=j
}
}
if(k!=i)
{
temp1=num[k]num[k]=num[i]num[i]=temp1
temp2=score[k]score[k]=score[i]score[i]=temp2
}
}
}
/* 函数功能:显示排序后学生学号和成绩 */
void PrintScore(int score[], long num[], int n)
{
int i
for(i=0i<ni++)
{
printf(" %10ld%4d\n",num[i],score[i])
}
}
/* 5、函数功能:按学号查询学生排名及其成绩*/
void SearchNum(int score[],long num[],int n)
{
long number
int i
printf("Please input the number you want to search:")
scanf("%ld",&number)
for(i=0i<ni++)
{
if(num[i]==number)
{
printf("%ld %d\n",num[i],score[i])
return
}
}
printf("\nNot found!\n")
}
/* 6、函数功能:统计个人类别的人数以及所占的百分比*/
void Statistics(int score[], int n)
{
int i,a=0,b=0,c=0,d=0,e=0
for(i=0i<ni++)
{
if(score[i]>=90)
{
a++
}
else if(score[i]>=80)
{
b++
}
else if(score[i]>=70)
{
c++
}
else if(score[i]>=60)
{
d++
}
else
{
e++
}
}
printf("优秀人数:%d\t占:%.3f%%\n良好人数:%d\t占:%.3f%%\n中等人数:%d\t占:%.3f%%\n及格人数:%d\t占:%.3f%%\n不及格人数:%d\t占:%.3f%%\n",a,(float)100*a/n,b,(float)100*b/n,c,(float)100*c/n,d,(float)100*d/n,e,(float)100*e/n)
}
/* 7、函数功能:输入学生学号、成绩、总分、平均分*/
void List(int score[], long num[], int n)
{
int i, j=0
for(i=0i<ni++)
{
printf("学号:%ld\t考试成绩:%d\n",num[i],score[i])
j+=score[i]
}
printf("课程总分:%d\n平均分:%.3f\n",j,(float)j/n)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)