帮我把子程序加到总程序中,我按讲的加了,就是调试错误
#include <stdio.h>#include <conio.h>
typedef struct Student
{
char name[255];
float score[4];
float avers;
}Student;
void main()
{
int i,j;
float sum;
Student s[10],tmp;
for(i=0;i<10;i++)
{
printf("输入第%d个学生的名字:",i+1);
scanf("%s",s[i].name);
sum=0;
for(j=0;j<3;j++)
{
printf("输入第%d个学生的第%d门课的成绩:",i+1,j+1);
scanf("%f",&s[i].score[j]);
sum+= s[i].score[j];
}
s[i].avers=sum*1.0/3;
}
for(i=0;i<10;i++)
for(j=0;j<3-i;j++)
if(s[j].avers< s[j+1].avers)
{
tmp=s[j];
s[j]=s[j+1];
s[j+1]=tmp;
}
printf("%-10s%-10s%-10s%-10s%-10s\n","姓名","课程1","课程2","课程3","平均分");
for(i=0;i<10;i++)
{
printf("%-10s",s[i].name);
for(j=0;j<3;j++)
printf("%-9.1f ",s[i].score[j]);
printf("%-9.1f\n",s[i].avers);
}
getch();
}
上面是我写的子程序,下面是总程序,我是第7个(void h7())
/*main()*/
#include<stdio.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<string.h>
void sort(char *name[],int n)
{char *pt;
int i,j,k;
for(i=0;i<n-1;i++)
{k=1;
for(j=i+1;j<n;j++)
if(strcmp(name[k],name[j])>0)k=j;
if(k!=i)
{pt=name[i];
name[i]=name[k];
name[k]=pt;}}}
void print(char*name[],int n)
{int i;
for(i=0;i<n;i++)
printf("%s\n",name[i]);}
void h1()
{static char *name[]={"CHINA","AMERICA","AUSTRALIA","RUSSIA","GERMAN"};
int n=5;
sort(name,n);
print(name,n);}
void h2()
{int a[10],max,n,i;
printf("enter 10 interger numbers:");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("\n");
for(i=1,max=a[0],n=0;i<10;i++)
{if(max<a[i])
{max=a[i];n=i;}}
printf("max=%d\n n=%d\n",max,n);}
int fac(int n)
{int f;
if(n<0)
printf("n<0,data error!");
else if(n==0||n==1)
f=1;
else f=fac(n-1)*n;
return(f);}
void h10()
{char S1[200],S2[100];
char *p,*q;
printf("请输出字符串s1:\n");
printf("请输出字符串s2:\n");
scanf("%s%s",S1,S2);
p=S1;q=S2;
while(*p++);
p--;
while(*q)
{*p=*q;p++;q++;}
*p='\0';
printf("连接以后\ns1=%s\n",S1);
}
main()
{ int a;
do{
printf(" 1.调用函数1\n");
printf(" 2.调用函数2\n");
printf(" 3.调用函数3\n");
printf(" 4.调用函数4\n");
printf(" 5.调用函数5\n");
printf(" 6.调用函数6\n");
printf(" 7.调用函数7\n");
printf(" 8.调用函数8\n");
printf(" 9.调用函数9\n");
printf(" 10.调用函数10\n");
printf(" 11.请退出\n");
printf(" 请选择:\n");
scanf("%d",&a);
switch(a)
{case 1 : h1();break;
case 2: h2();break;
case 10: h10();break;
}
}while(a!=11);
exit(0);
}
[ 本帖最后由 yxf2328063 于 2013-12-20 17:13 编辑 ]