函数问题
一个问题:我的程序要求写一个函数
把一个数组的的元素重新排列,按照从大到小的顺序。
用顺序之间穿插循环结构没有问题。
用函数就不成功了。
下面附上代码。热心的兄弟姐妹帮忙看看吧。
顺序之间穿插循环结构
#include "stdafx.h"
#include <stdio.h>
void main()
{
int amountStd=0;// the stundets' amount
int i=0, j=0;//counter
int classs[10];
int a,b,c,d,e;//level
char subject[10];
float scoreStd[200];
float min=0;
double sum=0;
double average;
printf("Please Enter the class number:");
scanf("%s",classs);
printf("\nPlease Enter the amount of all the students:");
scanf("%d",&amountStd);
scoreStd[amountStd] = '\0';
fflush(stdin);
printf("\nPlease Enter the subject:");
scanf("%c",subject);
fflush(stdin);
printf("\nPlease Enter the score of each student:");
for (i=0; i<amountStd; i++)//scan the amount
{
scanf("%f",&scoreStd[i]);
sum = sum + scoreStd[i];
if (scoreStd[i] >= 90 && scoreStd[i] <= 100) a++;
if (scoreStd[i] >= 80 && scoreStd[i] <= 89) b++;
if (scoreStd[i] >= 70 && scoreStd[i] <= 79) c++;
if (scoreStd[i] >= 60 && scoreStd[i] <= 69) d++;
if (scoreStd[i] >=0 && scoreStd[i] <= 59) e++;
}
for(i=0; i<amountStd; i++)//
{
for(j=amountStd; j>i; j--)
{
if (scoreStd[j] > scoreStd[j-1])
{
min=scoreStd[j-1]; scoreStd[j-1]=scoreStd[j]; scoreStd[j]=min;
}
}
}
average = sum / amountStd;
}
函数结构
#include "stdafx.h"
#include <stdio.h>
static int a=0, b=0, c=0, d=0, e=0;
void main()
{
int classs[20];
int amountStd=0;
int i=0;//counter
float *scoreStd[200];
char subject[20];
float sum=0;
float average;
float inscore(void);//fution
void levelf(float temps);
float sumf(char tempa,char tempb);
float averagef(float sum,int amountStd);
float *taxisf(float *scoreStd[],int amountStd);
printf("");
printf("Please Enter the class:");
scanf("%s",classs);
fflush(stdin);
printf("\nPlease Enter the amount of all the students:");
scanf("%d",&amountStd);
scoreStd[amountStd] = '\0';
fflush(stdin);
printf("\nPlease Enter the subject:");
scanf("%c",subject);
printf("\nPlease Enter score of each students:");
for (i=0; i<amountStd; i++)
{
*scoreStd[i] = inscore();//fution
levelf(*scoreStd[i]);//level
sum = sumf(*scoreStd[i],sum);
}
taxisf(*scoreStd[],amountStd);
average = averagef(sum,amountStd);
}
float inscore(void)
{
float temps;
return(scanf("%f",&temps));
}
void levelf(float temps)
{
if (temps >= 90 && temps <= 100) a++;
if (temps >= 80 && temps <= 89) b++;
if (temps >= 70 && temps <= 79) c++;
if (temps >= 60 && temps <= 69) d++;
if (temps >=0 && temps <= 59) e++;
}
float sumf(char tempa,char tempb)
{
tempa = tempa +tempb;
return (tempa);
}
float averagef(float sum,int amountStd)
{
return ( sum / amountStd);
}
float *taxisf(float *scoreStd[],int amountStd)
{
int i=0,j=0;
float *min=0;
for(i=0; i<amountStd; i++)//
{
for(j=amountStd; j>i; j--)
{
if (scoreStd[j] > scoreStd[j-1])
{
min=scoreStd[j-1]; scoreStd[j-1]=scoreStd[j]; scoreStd[j]=min;
}
}
}
return (*scoreStd);
}
谢谢了