我是大一新生新学数组,编了一个计成绩的C语言程序,看不懂程序错在哪,请帮一下忙。谢谢!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我是大一新生新学数组,编了一个计成绩的C语言程序,看不懂程序错在哪,请帮一下忙。谢谢!相关的知识,希望对你有一定的参考价值。
#include<stdio.h>
#define ARR_SIZE 30
int ReadScore(int num[], float score[]);
int GetFail(int num[], float score[], int n);
float GetAver(float score[], int n);
int GetAboveAver(int num[], float score[], int n);
void GetDetail(float score[], int n);
main()
int n, num[ARR_SIZE], fail, aboveAver;
float a;
float score[ARR_SIZE];
printf("Please enter num and score until score<0:\n");
n = ReadScore(num, score);
printf("Total students:%d\n", n);
fail = GetFail(num, score, n);
printf("Fail students = %d\n",fail);
a=GetAver( score, n);
printf("average is %f",a);
aboveAver = GetAboveAver(num, score,n,a);
printf("Above aver students = %d\n", aboveAver);
GetDetail(score, n);
int ReadScore(int num[],float score[])
int i,n;
printf("Please enter the num and score:");
for(i=1;i<=30;i++)
scanf("%d",&num[i]);
scanf("%f",&score[i]);
printf("%d,%-2f\n",num[i],score[i]);
if (score[i]<0)
break;
n++;
return n;
int GetFail(num,score,n)
int i,t=0;
for (i=1;i<=n;i++)
if(score[i]<60)
printf("%d-----%f\n",num[i],score[i]);
t++;
return t;
float GetAver(float score[], int n)
int i;
float sum=0,ave;
for(i=1;i<=n;i++)
sum=score[i]+sum;
ave=sum/n;
return ave;
int GetAboveAver(int num[], float score[], int n,int a)
int i,j;
for (i=1;i<=n;i++)
if (score[i]>a)
printf("%d------%d",num[i],score[i]);
j++;
return j;
void GetDetail(score[],int n)
int i;
float count[7]=0;
for (i=1;i<=n;i++)
if (score[i]<60)
count[1]++;
if (score[i]>60&&score[i]<69)
count[2]++;
if (score[i]>70&&score[i]<79)
count[3]++;
if (score[i]>80&&score[i]<89)
count[4]++;
if (score[i]>90&&score[i]<99)
count[5]++;
if (score[i]==100)
count[6]++;
printf("<60 %d %d\n", count[1], (count[1]/n)*100%);
printf("60-69 %d %d\n",count[2], (count[2]/n)*100%);
printf("70-79 %d %d\n",count[3], (count[3]/n)*100%);
printf("80-89 %d %d\n",count[4], (count[4]/n)*100%);
printf("90-99 %d %d\n",count[5], (count[5]/n)*100%);
printf("100 %d %d\n", count[6], (count[6]/n)*100%);
7行左右改成:int GetAboveAver(int num[], float score[], int n, int);
47行左右改成:int GetFail(int* num, float * score,int n)
84行最优,改成:void GetDetail(float score[],int n)
114到120行 100后面没百分号。
想想我大一的时候没这么勤奋啊,呵呵,加油啊。 参考技术A 数组都不懂,能写出这么长的程序?抄的吧……
以上是关于我是大一新生新学数组,编了一个计成绩的C语言程序,看不懂程序错在哪,请帮一下忙。谢谢!的主要内容,如果未能解决你的问题,请参考以下文章