C语言程序设计课后习题答案(第四版)谭浩强 下载本文

sort(str);

printf(\ for (i=0;i

void sort(char str[]) {int i,j; char t;

for(j=1;j

for (i=0;(istr[i+1]) {t=str[i]; str[i]=str[i+1]; str[i+1]=t; } } 7-12

#include <> #include <> int main()

{float solut(float a,float b,float c,float d); float a,b,c,d;

printf(\

scanf(\ printf(\ return 0; }

float solut(float a,float b,float c,float d) {float x=1,x0,f,f1; do

{x0=x;

f=((a*x0+b)*x0+c)*x0+d; f1=(3*a*x0+2*b)*x0+c; x=x0-f/f1; }

while(fabs(x-x0)>=1e-3); return(x); }

7-13

#include <> #define N 10 #define M 5

float score[N][M];

float a_stu[N],a_cour[M]; int r,c;

int main() { int i,j; float h;

float s_var(void); float highest();

void input_stu(void); void aver_stu(void); void aver_cour(void); input_stu(); aver_stu(); aver_cour();

printf(\ NO. cour1 cour2 cour3 cour4 for(i=0;i

{printf(\ for(j=0;j

printf(\ printf(\ }

printf(\ for (j=0;j

printf(\ printf(\ h=highest();

printf(\ NO. - course -\\n\ printf(\ return 0; }

void input_stu(void) {int i,j;

for (i=0;i

{printf(\ for (j=0;j

scanf(\

cour5 aver\\n\ } }

void aver_stu(void) {int i,j; float s;

for (i=0;i

{for (j=0,s=0;j

void aver_cour(void) {int i,j; float s;

for (j=0;j

for (i=0;i

float highest() {float high; int i,j;

high=score[0][0]; for (i=0;ihigh) {high=score[i][j]; r=i+1; c=j+1; }

return(high); }

float s_var(void) {int i;

float sumx,sumxn; sumx=; sumxn=;

for (i=0;i

{sumx+=a_stu[i]*a_stu[i]; sumxn+=a_stu[i]; }

return(sumx/N-(sumxn/N)*(sumxn/N)); }

7-*14

#include <> #define N 10 #define M 5

float score[N][M];

float a_stu[N],a_cour[M]; int r,c;

int main() { int i,j; float h;

float s_var(void); float highest();

void input_stu(void); void aver_stu(void); void aver_cour(void); input_stu(); aver_stu(); aver_cour();

printf(\ NO. cour1 cour2 cour3 cour4 for(i=0;i

{printf(\ for(j=0;j

printf(\ printf(\ }

printf(\ for (j=0;j

printf(\ printf(\ h=highest();

printf(\ NO. - course -\\n\ printf(\ return 0; }

cour5 aver\\n\