拒绝C编程中的浮点数 [英] Reject float number in C PROGRAMMING

查看:116
本文介绍了拒绝C编程中的浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< stdio.h>
 void  main( void )
{
浮动  int  int_test( float );
printf(" );
scanf(" ,& value);
同时(!=  0 )
{
int_test();
printf(" );
scanf(" ,& value);
}
}
 int  int_test( float  a)
{
 int 结果;
如果(a< 0)
{
printf(" );
结果= -1;
返回结果;
}
否则 如果((a> 0)&&(( int )(a-a&0; 0))
{
printf(" );
结果=  0 ;
返回  0 ;
}
其他
{
printf(" ,a);
返回
}
} 



我收到一个错误,当我输入浮点数时,它应该给我输出屏幕,该数字不是整数,但它显示的是直接浮点数NUNMBER ..我可以知道我的编码错误在哪里吗? class ="h2_lin">解决方案

此语句没有任何意义:

(int)(a-a>0)


我想你想要的是:

((a-(int)a)>0)


#include <stdio.h>
void main(void)
{
float value;
int int_test(float);
printf("Your Number: ");
scanf("%f", &value);
while (value !=0)
{
int_test(value);
printf("Your Number: ");
scanf("%f", &value);
}
}
int int_test(float a)
{
int result;
if (a<0)
{
printf("The number you have entered is negative\n");
result = -1;
return result;
}
else if ((a>0) && (int)(a-a>0))
{
printf("The number you have entered is not an integer\n");
result = 0;
return 0;
}
else
{
printf("The number you have entered is %g\n",a);
return a;
}
}



I got an error that when i key in the float number it should be giving me the output screen that the number is not an integer, but it show the DIRECTLY FLOAT NUNMBER..may i know where is the error of my coding?

解决方案

This statement doesn''t make any sense:

(int)(a-a>0)


I think what you want is:

((a-(int)a)>0)


这篇关于拒绝C编程中的浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆