急求几道C语言题的答案!求各位帮帮忙!

来源:百度知道 编辑:UC知道 时间:2024/06/26 02:47:55
1、学生的纪录由学号和成绩组成,N名学生的数据在主函数中放入结构体数组s中,请编写函数fun,它的功能是:按分数的高低排学生的纪录,高分在前。在主函数中调用函数fun,并输出结果。
2、编写函数fun,其功能是:实现矩阵(3行3列)的转置。在主函数中调用函数fun,并输出结果。

第一个问题的答案,VC++6.0环境测试通过
#include "stdio.h"
#include "string.h"
struct sdu
{
int cj;
int mun;
};
void fun(sdu s[ ])
{
sdu t;
for(int i=0;i<2;i++)
for(int j=1;j<3;j++)
{
if(s[i].cj<s[j].cj)
{
t=s[i];
s[i]=s[j];
s[j]=t;
}
}
for(int k=0;k<3;k++)
printf("%d,%d \n",s[k].cj,s[k].mun);
}
void main()
{
sdu s[3];
s[0].cj=60; s[0].mun=100;
s[1].cj=59; s[1].mun=101;
s[2].cj=67; s[2].mun=102;
fun(s);
}

第二个问题:
#include "stdio.h"

void main()
{
int i,j;
int s[3][3]={1,2,3,4,5,6,7,8,9};
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d ",s[i][j]);
printf("\n");
}
printf("\n");
printf("\n");
int t[