华中科技大学标准C语言程序设计及应用习题答案 下载本文

文档仅供参考,不当之处,请联系改正。

/*Input two string*/ printf(\ gets(str1);

printf(\

gets(str2);

/*Get the end of str1*/ for(i=0; i<80; i++) {

if(str1[i]=='\\0')

break;

}

/*Copy str2 to str1*/

for(j=i,k=0; str2[k]!='\\0';k++,j++)

str1[j]=str2[k];

str1[i+k]='\\0';

puts(str1);

} 5.6

#include

struct student

2020年4月19日

29

文档仅供参考,不当之处,请联系改正。

{char name[20]; int score; }stu[5],stu1;

void main(void) { int i,j;

printf(\student's score and name(5),seperate using the

character of ',' :\\n\

for(i=0; i<5; i++)

scanf(\

/*sorting*/

for(i=0; i<5; i++) for(j=0; j<4-i; j++)

if(stu[j].score>stu[j+1].score)

{stu1=stu[j];stu[j]=stu[j+1];stu[j+1]=stu1;}

} 5.7

printf(\ for(i=0; i<5; i++)

printf(\

#include main()

30

2020年4月19日

文档仅供参考,不当之处,请联系改正。

{ int a[3][3],i,j,m,n,o,p;

printf(\

for (i=0;i<=2;i++)

for (j=0;j<=2;j++)

scanf(\

for (i=0;i<=2;i++)

{ m=(a[i][0]>a[i][1])? a[i][0]:a[i][1];

n=(m>a[i][2])? m: a[i][2]; }

for (j=0;j<=2;j++)

{ o=(a[0][j]

2020年4月19日

31

文档仅供参考,不当之处,请联系改正。

p=(o

printf(\

else

printf(\ } 5.8

#include

void main(void)

{ int a[4][3],b[3][4],i,j;

for(i=0; i<4; i++) { for(j=0; j<3; j++) scanf(\

}

2020年4月19日

32