#include<stdio.h>
#include<math.h>
float f1(int a,int b,int c)
{
float x1,x2;
x1=(-b+sqrt(b*b-4*a*c))/2*a;
x2=(-b-sqrt(b*b-4*a*c))/2*a;
int s[2]={x1,x2};
return s[2];
}
main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(b*b-4*a*c>0) printf("x1=%d x2=%d",f1(a,b,c));
}
返回值的设置是不是出现了问题?运行出来x1,x2都等于0
#include<math.h>
float f1(int a,int b,int c)
{
float x1,x2;
x1=(-b+sqrt(b*b-4*a*c))/2*a;
x2=(-b-sqrt(b*b-4*a*c))/2*a;
int s[2]={x1,x2};
return s[2];
}
main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(b*b-4*a*c>0) printf("x1=%d x2=%d",f1(a,b,c));
}
返回值的设置是不是出现了问题?运行出来x1,x2都等于0