你这个程序要达到的目的是求出所有各学科的平均分、数学的最高分,英语最低分,以及满分的人数,程序中/*...*/之间的东西是注释,不进行编译的,再就是第三个求平均分的函数里面也许是你输入错误?应当是求stu[i].c的分吧,再就是把点号写成逗号,或语句结束没加分号等,具体改正说明见如下注释,希望能对你有所帮助。
#include "stdio.h"
struct student
{int number;
char name[15];
float english;
float math;
float c;
}stu[10]={{01,"aaa",99.0,100.0,82.0},
{02,"aab",85.0,90.0,100.0},
{03,"aac",99.0,99.0,45.0},
{04,"aad",85.0,45.0,78.0},
{05,"aae",99.0,100.0,100.0},
{06,"aaf",65.0,85.0,25.0},
{07,"aag",80.0,100.0,98.0},
{08,"aah",78.0,98.0,96.0},
{09,"aai",78.0,98.0,98.0},
{10,"aao",100.0,100.0,100.0}}; /*定义一个结构体数组并赋值,此处的注释符号不要的*/
float average11() /*求数学科目的平均分*/
{int i;
float average1=0,sum1=0; /*定义变量还得初始化呀*/
for(i=0;i<10;i++)/*要用个类似for循环语句求所有的数学分之和*/
sum1=sum1+stu[i].math;
average1=sum1/10;
return average1;
}
float average22() /*求英语科目的平均分*/
{int i;
float average2=0,sum2=0; /*定义变量还得初始化呀*/
for(i=0;i<10;i++)/*要用个类似for循环语句求所有的英语分之和*/
sum2=sum2+stu[i].english;
average2=sum2/10;
return average2;
}
float average33() /*求c科目的平均分*/
{int i;
float average3=0,sum3=0; /*定义变量还得初始化呀*/
for(i=0;i<10;i++)/*要用个类似for循环语句求所有的c分之和*/
sum3=sum3+stu[i].c; /*此处应当是求c的平均数吧?*/
average3=sum3/10;
return average3;
}
float maxx() /*求数学科目的最高分*/
{int i;
float max;
max=stu[0].math; /*stu[0].math里面应当是符号.不是逗号,将第一个数学分赋予max*/
for(i=1;i<10;i++) /*此处i初始值改为1,即从第二个数学分开始和第一个数学分比较大小*/
if(max
return max;
}
float minn() /*求英语科目的最低分*/
{int i;
float min;
min=stu[0].english; /*stu[0].english里面应当是符号.不是逗号,将第一个英语分赋予min*/
for(i=1;i<10;i++) /*此处i初始值改为1,即从第二个英语分开始和第一个英语分比较大小*/
if(min>stu[i].english)
min=stu[i].english; /*stu[0].english里面应当是符号.不是逗号,*/
return min;
}
int countt() /*统计c科目满分100的个数*/
{int i,count=0;
for(i=0;i<10;i++) /*使用循环语句啊!*/
if(stu[i].c==100)
count++;
return count;
}
/*还是注释符号的问题*/
main()
{int i,count;/* 重复定义i干吗呢?*/
float max,min,average1,average2,average3; /*还是注释符号的问题*/
max=maxx();
min=minn();
average1=average11();
average2=average22();
average3=average33();
count=countt();/*还是注释符号的问题,且语句后面要以分号;结束呀*/
printf("number name english math c\n"); /*num应当是name吧!*/
for(i=0;i<10;i++)
printf("%d %s %f %f %f \n",stu[i].number,stu[i].name,stu[i].english,stu[i].math,stu[i].c);
printf("average\n"); /*还是注释符号的问题*/
printf("%f,%f,%f\n",average1,average2,average3);
printf("shuxuezuidazhi\n");
printf("%f\n",max);
printf("yingyuzuixiaozhi\n");
printf("%f\n",min);
printf("cyuyanmanfen\n");
printf("%d\n",count);/*还是注释符号的问题*/
}
switch后面少{
所有CASE后面应该加: 不是 ;
同样,DEFAULT 后面也是 : 不是;
而且,你的这里:
default;
wo[k++]=s[i++];
else
break;
}
return 0;
}
也不对,RETURN 0上面的}位置错了,应该是:
default;
wo[k++]=s[i++];
}
else
break;
return 0;
}
不过,其实这里不需要再写个
else
break;
直接打个空语句就可以了。
最后,你少了个} 因为你的 }是用来结束while 的
另外有个错误(因为不知道你的意图):if(strcmp(a,m[j])==1)
这里,strcmp是指后者减去前者的差,如果是一样的话,值应该是0
也许你因该改成if(strcmp(a,m[j])==0)
这个你看看可以不?
#include
#include
int add(char a[])
{
int j;
char *m[10]={"one","two","three","four","five","six","seven","eight","nine","zero"};
for(j=0;j<=9;j++)
if(strcmp(a,m[j])==1)
return j;
}
int main()
{
int i,a=0,b=0,k=0;
char s[100],wo[50]={'\0'};
while(1)
{
gets(s);
if(s[0]!='0')
for(i=0;s[i]!='\0'; )
switch(s[i])
{
case ' ':
{wo[k]='\0';
a=a*10+add(wo);
b=b+a;
a=0;
i++;
break;
}
case '+':
{wo[k]='\0';
a=a+10+add(wo);
b=b+a;
a=0;
i++;
break;
}
case '=':
{printf("%d",b);
break;}
default:
wo[k++]=s[i++];
}
;
return 0;
}
}
在你这个基础上,修改好了,能运行出结果!
#include "stdio.h"
struct student
{
int number;
char name[15];
float english;
float math;
float c;
}stu[10]={
{1,"aaa",99.0,100.0,82.0},
{2,"aab",85.0,90.0,100.0},
{3,"aac",99.0,99.0,45.0},
{4,"aad",85.0,45.0,78.0},
{5,"aae",99.0,100.0,100.0},
{6,"aaf",65.0,85.0,25.0},
{7,"aag",80.0,100.0,98.0},
{8,"aah",78.0,98.0,96.0},
{9,"aai",78.0,98.0,98.0},
{10,"aao",100.0,100.0,100.0}};
float average11()
{
int i;
float average1,sum1=0;
for(i=0;i<10;i++)
{
sum1=sum1+stu[i].math;
}
average1=sum1/10;
return average1;
}
float average22()
{
int i;
float average2,sum2=0;
for(i=0;i<10;i++)
{
sum2=sum2+stu[i].english;
}
average2=sum2/10;
return average2;
}
float average33()
{
int i;
float average3,sum3=0;
for(i=0;i<10;i++)
{
sum3=sum3+stu[i].english;
}
average3=sum3/10;
return average3;
}
float maxx()
{
int i;
float max;
max=stu[0].math;
for(i=0;i<10;i++)
if(max=stu[i].math)
max=stu[i].math;
return max;
}
float minn()
{
int i;
float min;
min=stu[0].english;
for(i=0;i<10;i++)
if(min>stu[i].english)
min=stu[i].english;
return min;
}
int countt()
{
int i,count=0;
for(i=0;i<10;i++)
if(stu[i].c==100)
count++;
return count;
}
main()
{
float max,min,average1,average2,average3;
int i,count=0;
max=maxx();
min=minn();
average1=average11();
average2=average22();
average3=average33();
count=countt();
printf("number num english math c\n");
for(i=0;i<10;i++)
printf("%d %s %f %f %f \n",stu[i].number,stu[i].name,stu[i].english,stu[i].math,stu[i].c);
printf("average\n");
printf("%f,%f,%f\n",average1,average2,average3);
printf("shuxuezuidazhi\n");
printf("%f\n",max);
printf("yingyuzuixiaozhi\n");
printf("%f\n",min);
printf("cyuyanmanfen\n");
printf("%d\n",count);
}
#include
struct student
{
int number;
char name[15];
float english;
float math;
float c;
};
float Average(student st[],char *subject)
{
float sum=0;
if ("math"==subject||"Math"==subject) //Math
{
for (int i=0;i<10;i++)
{
sum+= st[i].math;
}
}
else if ("English"==subject||"english"==subject) //English
{
for (int i=0;i<10;i++)
{
sum+= st[i].english;
}
}
else if ("C"==subject||"c"==subject) //C成绩
{
for (int i=0;i<10;i++)
{
sum+= st[i].c;
}
}
else //都不是,置0
{
return 0;//
}
return (sum/10);//返回平均成绩
}
float MaxMin(student st[],char *subject,char *valueType)
{
float maxS,minS;
if ("math"==subject||"Math"==subject)
{
minS=st[0].math;
maxS=st[0].math;//
for (int i=1;i<10;i++)
{
if (st[i].math>maxS)
{
maxS=st[i].math;
}
if (st[i].math
minS=st[i].math;
}
}
}
else if ("English"==subject||"english"==subject)
{
minS=st[0].english;
maxS=st[0].english;//
for (int i=1;i<10;i++)
{
if (st[i].english>maxS)
{
maxS=st[i].english;
}
if (st[i].english
minS=st[i].english;
}
}
}
else if ("C"==subject||"c"==subject)
{
minS=st[0].c;
maxS=st[0].c;//
for (int i=1;i<10;i++)
{
if (st[i].c>maxS)
{
maxS=st[i].c;
}
if (st[i].c
minS=st[i].c;
}
}
}
else
{
return 0;
}
//-----------------------------------
if (valueType=="max"||valueType=="Max")
{
return maxS;
}
else if (valueType=="min"||valueType=="Min")
{
return minS;
}
else
{
return 0;
}
}
void main()
{
struct student stu[]={
{1,"aaa",99.0,100.0,82.0},
{2,"aab",85.0,90.0,100.0},
{3,"aac",99.0,99.0,45.0},
{4,"aad",85.0,45.0,78.0},
{5,"aae",99.0,100.0,100.0},
{6,"aaf",65.0,85.0,25.0},
{7,"aag",80.0,100.0,98.0},
{8,"aah",78.0,98.0,96.0},
{9,"aai",76.0,96.0,98.0},
{10,"aaj",100.0,100.0,100.0}
};
printf("--------------AvgValue------------\n");
printf(" Math:%f\n English:%f\n C:%f\n",Average(stu,"Math"),Average(stu,"English"),Average(stu,"C"));
printf("--------------MaxValue------------\n");
printf(" Math:%f\n English:%f\n C:%f\n",MaxMin(stu,"Math","max"),MaxMin(stu,"English","max"),MaxMin(stu,"C","max"));
printf("--------------MinValue------------\n");
printf(" Math:%f\n English:%f\n C:%f\n",MaxMin(stu,"Math","min"),MaxMin(stu,"English","min"),MaxMin(stu,"C","min"));
}