+ 1
Can anyone help me
Write a program that inputs a series of integers and passes them one at a time to function bool isEven(int a), that determine whether an integer is even. The function should take an integer argument and return true if the integer is even and false otherwise.
4 Answers
+ 1
the following is the code:
int even(int value)
{
if(value % 2 == 0){
cout<<"the value is even:"<<value;
}
main(){
even(12);
+ 3
i'd recommend not to check the oddity by %2 but to use bitwise operator &
it is faster and closer to assembly language
it would look like:
return !(a & 1);
returns 0 (!1) if last bit is 1 - not even
or 1 (!0) if last bit is 0 - even
+ 2
by using integer%2==0ļ¼true if even.
0
In array