C语言中问题warning C4244: 'function' : conversion from 'double ' to 'int ', possible loss of data
warningC4244:'function':conversionfrom'double'to'int',possiblelossofdatawarningC4761:...
warning C4244: 'function' : conversion from 'double ' to 'int ', possible loss of data
warning C4761: integral size mismatch in argument; conversion supplied
哪里出错了,怎么改啊
#include<stdio.h>
int main()
{
double sign(int x);
double a,b;
scanf("%lf",&a);
b=sign(a);
printf("%.1lf\n",b);
return 0;
}
double sign(int x)
{
double c;
if(x>0)
c=x*2.5;
else if(x==0)
c=0;
else if(x<0)
c=x*x;
return c;
} 展开
warning C4761: integral size mismatch in argument; conversion supplied
哪里出错了,怎么改啊
#include<stdio.h>
int main()
{
double sign(int x);
double a,b;
scanf("%lf",&a);
b=sign(a);
printf("%.1lf\n",b);
return 0;
}
double sign(int x)
{
double c;
if(x>0)
c=x*2.5;
else if(x==0)
c=0;
else if(x<0)
c=x*x;
return c;
} 展开
1个回答
2015-11-21
展开全部
#include<stdio.h>
double sign(double x);
int main()
{
double a,b;
scanf("%lf",&a);
b=sign(a);
printf("%.1lf\n",b);
return 0;
}
double sign(double x)
{
double c;
if( (int)(x) > 0)
c = x*2.5;
else if( (int)(x) == 0)
c = 0;
else if((int)(x) < 0)
c = x*x;
return c;
}
建议在函数sign里面实现,类型强制转化。
追问
除了这个 还能有其他改法吗
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询