中易网

C++程序设计判断奇偶性

答案:5  悬赏:0  
解决时间 2021-03-22 22:28
#include
using namespace std;
int main()
{
int input;
cout<<"which number do you want to test:\n";
cin>>input;

if (input%2) cout<<"number"< else cout<<"number"< return 0;
}
当输入23.5时 显示的为23,并又结果 怎样避免
最佳答案
把输入参数从int改为float或者double试试,因为int只记录整数位,小数位会根据环境设置(没改过就是默认的)抹掉或者升降(直接加1或者四舍五入,不确定)。
全部回答
input 是个关键字,不可以做标示符的。 再说,你定义的是int型的,输入小数,会自动转换为int 向下取整 对于判断奇数偶数都是对整数而言。
#include using namespace std; int main() { unsigned int x; cin>>x; if((x%0xff)%2==0) cout<<"x低16位为偶数!"<
  • 3楼网友:伤口狠精致
  • 2021-03-22 02:29
解法一:用函数重载做 #include using namespace std; void fun(int f) { int a = (int)f; if ((*(int *)&f) == (*(int *)&a)) { cout<<"number"< using namespace std; int main(){ int error=0; int i=0; char a[20]; cout<<"which number do you want to test:\n"<
  • 4楼网友:滚出爷的世界
  • 2021-03-22 00:54
解法一:用函数重载做 #include using namespace std; void fun(int f) { int a = (int)f; if ((*(int *)&f) == (*(int *)&a)) { cout<<"number"< using namespace std; int main(){ int error=0; int i=0; char a[20]; cout<<"which number do you want to test:\n"<
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯