本文介绍了这个数字很奇怪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何验证C ++中的数字是否为奇数?


谢谢你,最好的问候。

加埃塔诺

Hi to all,
How can verify if a number is odd in C++?

Thank You and best Regards.
Gaetano

推荐答案



如果数字是标量,那么你可以这样做:


bool odd = !!(数字& 1);


david

If the number is a scalar, then you can do this:

bool odd = !!(number & 1);

david




你可以像大卫建议的那样做 - 或者更喜欢不那么模糊(和

一样快)

数字%2!= 0

/ Peter

You can do as David suggested - or prefer the less obscure (and at
least as fast)
number % 2 != 0

/Peter




如果数字是标量,那么你可以这样做:


bool odd = !!(数字& 1);


david


If the number is a scalar, then you can do this:

bool odd = !!(number & 1);

david



为什么!! ?

Why !! ?


这篇关于这个数字很奇怪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:05