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

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

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

}

void insert(char str[]) {int i;

for (i=strlen(str);i>0;i--) {str[2*i]=str[i]; str[2*i-1]=' '; }

printf(\} 7-9

#include

int letter,digit,space,others; int main()

{void count(char []); char text[80];

printf(\ gets(text);

printf(\ puts(text); letter=0; digit=0; space=0; others=0; count(text);

printf(\ return 0; }

void count(char str[]) {int i;

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

if ((str[i]>='a'&& str[i]<='z')||(str[i]>='A' && str[i]<='Z')) letter++;

else if (str[i]>='0' && str [i]<='9') digit++;

else if (str[i]==32) space++; else

others++; } 7-10

#include #include int main()

{int alphabetic(char); int longest(char []); int i;

char line[100];

printf(\ gets(line);

printf(\

for (i=longest(line);alphabetic(line[i]);i++) printf(\ printf(\ return 0; }

int alphabetic(char c)

{if ((c>='a' && c<='z')||(c>='A'&&c<='z')) return(1); else

return(0); }

int longest(char string[])

{int len=0,i,length=0,flag=1,place=0,point; for (i=0;i<=strlen(string);i++) if (alphabetic(string[i])) if (flag) {point=i; flag=0; } else

len++; else

{flag=1;

if (len>=length) {length=len; place=point; len=0; } }

return(place); }

7-11

#include #include #define N 10 char str[N]; int main()

{void sort(char []); int i,flag;

for (flag=1;flag==1;)

{printf(\ scanf(\ if (strlen(str)>N)

printf(\ else

flag=0; }

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 for(i=0;i

{printf(\ for(j=0;j

printf(\ printf(\

cour3 cour4

cour5 aver\\n\

}

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

float highest() {float high;

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

}voidinsert(charstr[]){inti;for(i=strlen(str);i>0;i--){str[2*i]=str[i];str[2*i-1]='';}printf(\}7-9#includeintletter,d
推荐度:
点击下载文档文档为doc格式
87azb13lxw6x2111f20r4n7xz5ee5l00bm8
领取福利

微信扫码领取福利

微信扫码分享