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

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

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

void lcd(int,int); int u,v;

scanf(\ hcf(u,v); lcd(u,v);

printf(\ printf(\ return 0; }

void 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; } Hcf=v; }

void lcd(int u,int v) {

Lcd=u*v/Hcf; } 7-2

#include #include float x1,x2,disc,p,q; int main()

{void greater_than_zero(float,float); void equal_to_zero(float,float); void smaller_than_zero(float,float); float a,b,c;

printf(\

scanf(\

printf(\ disc=b*b-4*a*c; printf(\ if (disc>0) {

greater_than_zero(a,b);

printf(\ }

else if (disc==0)

{equal_to_zero(a,b);

printf(\ } else

{smaller_than_zero(a,b);

printf(\ }

return 0; }

void greater_than_zero(float a,float b) {x1=(-b+sqrt(disc))/(2*a); x2=(-b-sqrt(disc))/(2*a); }

void equal_to_zero(float a,float b) {

x1=x2=(-b)/(2*a); }

void smaller_than_zero(float a,float b) {

p=-b/(2*a);

q=sqrt(-disc)/(2*a); } 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; }

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;

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

voidlcd(int,int);intu,v;scanf(\hcf(u,v);lcd(u,v);printf(\printf(\return0;}voidhcf(intu,intv){intt,r;if(v>u){t=u;u=v;v=t;}
推荐度:
点击下载文档文档为doc格式
87azb13lxw6x2111f20r4n7xz5ee5l00bm8
领取福利

微信扫码领取福利

微信扫码分享