C语言答案第6章
第6章
[习题-1]/*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);
}
[习题-2]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)
i=j=0; { putchar('-');n=-n;}
} if((i=n/10)!=0) stod(i);
} putchar(n%10+'0');
}
答案:(略)
[习题-3]/*c6_3.c*/
#include
#include
double s(double a,double b,double c)
{
double s,ss;
if(a+b
{
printf("Error Data");
return -1;
}
s=(a+b+c)/2;
ss=sqrt(s*(s-a)*(s-b)*(s-c));
printf("S=%lf",ss);
return ss;
}
void main()
{
int i;
double a,b,c;
for(i=0;i<10;i++)
{
scanf("%lf %lf %lf",&a,&b,&c);
s(a,b,c);
}
}
[习题-4]题-5]/*c6_5.c*/
#include
#include
void sort(int a[],int size)
{
int i,j,