C语言第6章
- 格式:ppt
- 大小:957.00 KB
- 文档页数:59
第6章函数和模块设计【习题6-1】更正下面函数中的错误。
(1)返回求x和y平方和的函数。
(2)返回求x和y为直角边的斜边的函数。
sum_of_sq(x,y) hypot(double x,double y){ {double x,y; h=sqrt(x*x+y*y);return(x*x+y*y); return(h);} }程序如下:/*c6_1(1).c*/ /*c6_1(2).c*/(1) (2)double sum_of_sq(double x,double y) double hypot(double x,double y) { {return(x*x+y*y); double h;} h=sqrt(x*x+y*y);return(h);}【习题6-2】说明下面函数的功能。
(1)itoa(int n,char s[ ])(2)int htod(char hex [ ]){ { int i,dec=0;static int i=0,j=0; for(i=0;hex[i]!='\0';i++)int c; { if(hex[i]>='0'&&hex[i]<='9') if(n!=0) dec=dec*16+hex[i]-'0';{ if(hex[i]>='A'&&hex[i]<='F') j++; dec=dec*16+hex[i]-'A'+10;c=n%10+'0'; if(hex[i]>='a'&&hex[i]<='f') itoa(n/10,s); dec=dec*16+hex[i]-'a'+10;s[i++]=c; }} return(dec);else }{ (3)void stod(int n)if(j==0) s[j++]='0'; { int i;s[j]='\0'; if(n<0){ putchar('-');n=-n;} i=j=0; if((i=n/10)!=0) stod(i);} putchar(n%10+'0');} }功能:(1)(略)(2)(略)【习题6-3】编写已知三角形三边求面积的函数,对于给定的3个量(正值),按两边之和大于第三边的规定,判别其能否构成三角形,若能构成三角形,输出对应的三角形面积。