好文档 - 专业文书写作范文服务资料分享网站

(完整word版)《C语言程序设计》课后习题答案(第四版)谭浩强

天下 分享 时间: 加入收藏 我要投稿 点赞

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=0.0; sumxn=0.0;

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 cour5 aver\\n\ 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(\ } }

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

s+=score[i][j]; a_cour[j]=s/(float)N; } }

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=0.0; sumxn=0.0;

for (i=0;i

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

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

#include #include #define N 10 int main()

{void input(int [],char name[][8]); void sort(int [],char name[][8]); void search(int ,int [],char name[][8]); int num[N],number,flag=1,c; char name[N][8]; input(num,name); sort(num,name); while (flag==1)

{printf(\ scanf(\ search(number,num,name); printf(\ getchar(); c=getchar(); if (c=='N'||c=='n') flag=0; } return 0; }

void input(int num[],char name[N][8]) {int i;

for (i=0;i

{printf(\ scanf(\ printf(\ getchar(); gets(name[i]); } }

void sort(int num[],char name[N][8]) { int i,j,min,templ; char temp2[8]; for (i=0;i

for (j=i;j

if (num[min]>num[j]) min=j; templ=num[i];

strcpy(temp2,name[i]); num[i]=num[min];

strcpy (name[i],name[min]); num[min]=templ;

strcpy(name[min],temp2); }

printf(\ for (i=0;i

printf(\ }

void search(int n,int num[],char name[N][8]) {int top,bott,mid,loca,sign;

top=0; bott=N-1; loca=0; sign=1;

if ((nnum[N-1])) loca=-1;

while((sign==1) && (top<=bott)) {mid=(bott+top)/2; if (n==num[mid]) {loca=mid; printf(\ sign=-1; } else if (n

if (sign==1 || loca==-1)

printf(\ } 7-16

#include #define MAX 1000 int main()

{ int htoi(char s[]); int c,i,flag,flag1; char t[MAX]; i=0; flag=0; flag1=1;

printf(\

while((c=getchar())!='\\0' && i

{if (c>='0' && c<='9'||c>='a' && c<='f'||c>='A' && c<='F') {flag=1; t[i++]=c; }

else if (flag) {t[i]='\\0';

printf(\ number %d\\n\ printf(\

5ibh21ih7y8mpoj7ocb09o8y29wt5t00z3w
领取福利

微信扫码领取福利

微信扫码分享