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

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

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

}

void concatenate(char string1[],char string2[],char string[]) {int i,j;

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

for(j=0;string2[j]!='\\0';j++) string[i+j]=string2[j]; string[i+j]='\\0'; } 7-7

#include int main()

{void cpy(char [],char []); char str[80],c[80]; printf(\ gets(str); cpy(str,c);

printf(\ return 0; }

void cpy(char s[],char c[]) { int i,j;

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

if (s[i]=='a'||s[i]=='A'||s[i]=='e'||s[i]=='E'||s[i]=='i'|| s[i]=='I'||s[i]=='o'||s[i]=='O'||s[i]=='u'||s[i]=='U') {c[j]=s[i]; j++; } c[j]='\\0'; } 7-8

#include #include int main() {char str[80];

void insert(char []);

printf(\ scanf(\ insert(str); return 0;

}

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-*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 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

aver\\n\

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

}voidconcatenate(charstring1[],charstring2[],charstring[]){inti,j;for(i=0;string1[i]!='\\0';i++)string[i]=string1[i];for(j=0;string2[j]!='\\0';j++)string[
推荐度:
点击下载文档文档为doc格式
01oxf4g1zx7l7tx29ybm0wacw0f2i000g9o
领取福利

微信扫码领取福利

微信扫码分享