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
{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 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 { 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 {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 {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 {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 void insert(char []); printf(\ scanf(\ insert(str); return 0; 请浏览后下载,资料供参考,期待您的好评与关注!
《C语言程序设计》课后习题答案(第四版)谭浩强
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)