1.#include <stdio.h>
#include <math.h>
void main()
{
float a,b,c,s,area; /*当我把这里的float改成double时就不行了*/
printf("Please input the lentghs of the sides:");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("The area is %g\n",area);
}
2.#include <stdio.h>
#include <math.h>
void main()
{
float a,b,c; /*还是的,当我把这里的float改成double或int就不行了*/
float x1,x2,mid_trm;
printf("Please input the three coefficients of the function:");
scanf("%f%f%f",&a,&b,&c);
if(a!=0)
{
mid_trm=b*b-4*a*c;
if(mid_trm>0)
{
x1=(-b+sqrt(mid_trm))/(2*a);
x2=(-b-sqrt(mid_trm))/(2*a);
printf("The two roots are %g, %g\n",x1,x2);
}
else if(mid_trm==0)
{
x1=-b/(2*a);
printf("It has only one root: %g\n",x1);
}
else
printf("It has no real root!\n");
}
else
{
if(b!=0)
printf("The root is %g\n",-c/b);
else if(c==0)
printf("It has infinite roots.\n");
else
printf("It has no root.\n");
}
}
问题正如程序的注释所注,我现在对float和double的用法有点迷惘
哪位高手能帮一下忙,解释一下,不胜感激!
我用的是VC++ 6.0
弑天下
慕森卡