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

else if ((ch[j]>='a') && (ch[j]<='z')) tran[j]=219-ch[j]; else

tran[j]=ch[j]; j++; } n=j;

printf(\ for (j=0;j

#include int main() {int j,n;

char ch[80];

printf(\ gets(ch);

printf(\ j=0;

while (ch[j]!='\\0')

{ if ((ch[j]>='A') && (ch[j]<='Z')) ch[j]=155-ch[j];

else if ((ch[j]>='a') && (ch[j]<='z')) ch[j]=219-ch[j]; else

ch[j]=ch[j]; j++; } n=j;

printf(\ for (j=0;j

#include int main()

{ char s1[80],s2[40]; int i=0,j=0;

printf(\

scanf(\

printf(\ scanf(\ while (s1[i]!='\\0') i++;

while(s2[j]!='\\0') s1[i++]=s2[j++]; s1[i]='\\0';

printf(\ return 0; } 7-1-1

#include int main()

{int hcf(int,int); int lcd(int,int,int); int u,v,h,l;

scanf(\ h=hcf(u,v);

printf(\ l=lcd(u,v,h);

printf(\ return 0; }

int hcf(int u,int v) {int t,r; if (v>u)

{t=u;u=v;v=t;} while ((r=u%v)!=0) {u=v; v=r;} return(v); }

int lcd(int u,int v,int h) {

return(u*v/h); } 7-3

#include int main()

{int prime(int); int n;

printf(\ scanf(\ if (prime(n))

printf(\ else

printf(\ return 0; }

int prime(int n) {int flag=1,i;

for (i=2;i

#include #define N 3 int array[N][N]; int main()

{ void convert(int array[][3]); int i,j;

printf(\ for (i=0;i

scanf(\ printf(\ for (i=0;i

printf(\ printf(\ }

convert(array);

printf(\ for (i=0;i

printf(\ printf(\ }

return 0; }

void convert(int array[][3])

{int i,j,t;

for (i=0;i

array[i][j]=array[j][i]; array[j][i]=t; } }

#include #include int main()

{void inverse(char str[]); char str[100];

printf(\ scanf(\ inverse(str);

printf(\ return 0; }

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

for (i=0,j=strlen(str);i<(strlen(str)/2);i++,j--) {t=str[i];

str[i]=str[j-1]; str[j-1]=t; } } 7-6

#include int main()

{void concatenate(char string1[],char string2[],char string[]); char s1[100],s2[100],s[100]; printf(\ scanf(\

printf(\ scanf(\

concatenate(s1,s2,s);

printf(\ return 0;