第二章
1.x++,3x1,Xf_1_4,a$#24,bg—1,I am不是标识符
3.1)2L转换成float类型,3转换成float型,012转换成float类型,44转换成float类型;
2)34转换成double类型,sqrt(34)转换成int类型,6转换成double类型,5转换成double类型,3*(int)sqrt(34)转换成double类型,0x2AF转换成double类型;
3)4转换成float类型,2.5f+4转换成double类型,6转换成Long类型,6*27L转换成double类型,1526转换成double,2.4L转换成double
4.1)
#include <stdio.h>
int main()
{
    printf("%f\n",3*(2L+4.5f)-012+44);
    return 0;
}      53.500000
2) #include <stdio.h>
#include <math.h>
int main()
{
    printf("%f\n",3*(int)sqrt(34)-sin(6)*5+0x2af);
    return 0;
}    703.397077
3)#include <stdio.h>
#include <math.h>
int main()
{
    printf("%f\n",cos(2.5f+4)-6*27L+1526-2.4L);
    return 0;
}      1362.576588
6. #include <stdio.h>
double weight(double p,double d)
{
    return p*3.1415926*d*d*d/6.0;
}
int main()
{
    printf("the weight of iron is :%f\n",weight(7.86,0.1));
    printf("the weight of gold is :%f\n",weight(19.3,0.15));
    return 0;
}  铁:0.004115 金:0.034106
7. #include <stdio.h>
#include <math.h>
int main()
{
    int a,b,c,d;
    double s,x1,x2;
    printf("please input three numbers:");
    scanf("%d,%d,%d",&a,&b,&c);
    d=b*b-4*a*c;
    if(d>0)
    {
        s=sqrt(d);
        x1=(-b+s)/2.0/a;
        x2=(-b-s)/2.0/a;
        printf("the result is:%f,%f\n",x1,x2);
    }
    else if(d==0)
    {
        x1=-b/2.0/a;
        printf("the result is:%f\n",x1);
    }
    else
        printf("error!\n");
    return 0;
}      error!
第三章
4.调用f函数时,1转换成float类型,第一个y转换成int型,函数体中n,4转换成float型,结果由float转换成Int型
6.
圆球体积:
double sphere_volume(double radius)
{
    return 3.14159*4*radius*radius*radius/3;
}
圆球表面积:
double sphere_area(double radius)
{
    return 3.14159*4*radius*radius;
}
圆柱体体积:
double cylinder_volume(double radius,double height)
{
    return 3.14159*radius*radius*height;
}
圆柱体表面积:
double cylinder_area(double radius,double height)
{
    return 2*3.14159*radius*radius+2*3.14159*radius*height;
}
7.1)全部用printf()输出
2)
#include <stdio.h>
double weight(double y,double x)
{
    return y*3.1415926*x*x*x/6.0;
}
int main()
{
    printf("the weight of gold is :%f\n",weight(7.86,0.1));
    printf("the weight of silver is :%f\n",weight(19.3,0.15));
printf("the weight of copper is :%f\n",weight(7.86,0.1));
printf("the weight of iron is :%f\n",weight(7.86,0.1));
printf("the weight of tin is :%f\n",weight(7.86,0.1));
    return 0;
}
这种写法程序长度并没有减少,但是减少出错几率,只需在函数中修改圆周率即可,第二种程序修改难度降低
float型3)
double weight(double y,double x)
{
    return y*x*x*x;
}
只需将此函数修改,主函数中程序不变
8. #include <stdio.h>
double tmax(double a,double b,double c)
{
    double max=a>b?a:b;
    return max>c?max:c;
}
int main()
{
    int  a,b,c;
    printf("please input three numbers:");
    scanf("%d,%d,%d",&a,&b,&c);
    printf("the biggest number is:%f\n",tmax(a,b,c));
    return 0;
}
9.double resistance(double r1,double r2)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。