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

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

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-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(\ c=getchar();

if (c=='N'||c=='n') flag1=0; else

{flag=0; i=0; printf(\ } } }

return 0; }

int htoi(char s[]) { int i,n; n=0;

for (i=0;s[i]!='\\0';i++)