Computer problems,Computer help
*AX SOFT>>>Programming & Design

Given an integer value input,determine if that value is even or odd?


write in pseudocode solution

void checkNumber(int number)
{
if(number is divisible by 2)
print "The number is even";
else
print "The number is odd";
}

public boolean isEven(int input)
{
return (input MOD 2) ;
}

Pseudocode?!?! you sure.... well ok

GET input integer
CALCULATE if input integer is even
DISPLAY result

If you want actual logic Pseudocode does not dabble with specifics but rather data flow... for logical answer Ashok has given you the solution... Mod the integer by 2. if it returns 0 its even if it returns 1 its odd.

10 INPUT NUMBER
20 REMAINDER = NUMBER MOD 2
30 IF REMAINDER < .1 THEN PRINT "Number - Even" ELSE PRINT "Number = Odd"
Hope this helps...

boolean IsEven(integer value){
return ((value mod 2) = 0);
}

boolean IsOdd(integer value){
return (value mod 2);
}

"mod" is a pretty common operator in many programming languages... it returns the modulus--the remainder.

Likewise, in most languages, 0 will convert to False, and 1 will convert to True when setting or returning a boolean value.

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • Open source dev operating system.?

    Gnome is just one of the GUI for Linux. Mac OS X already has a far superior GUI. Open source more refers to the licencing agreement of the software written then it does the operating system. Bas...

  • Command prompt got messed up?

    try to check ur 'PATH' environment variable. It should have at least this: %SystemRoot%\system32;%SystemRoot%;

    ...
  • Can you make me a design with my picture?

    Sure, I am pretty good with Photoshop. I can email you, and have it done by the weekend for sure, maybe even tonight depending on how much you would like done. If you aren't satisfied with ...

  • Can you please go to my blog? i need hits?

    its ok, i left comments on some ideas i had...^.^

    ...
  • Just finished my c++ encryption program. Anyone want to check my code?

    (1) ifstream KeyRead; KeyRead.open(EncrKey); if(!KeyRead.is_open()) { cerr << "File failed to open for read. Program ending." << endl; ...

  • Can a slideshow made in a vista work in a mac?

    The issue isn't actually whether the computer is running Windows XP, Vista or Mac OS X, but whether or not it has PowerPoint (or some compatible equivalent, like iWork or OpenOffice.org) insta...

  • Java Nested For Loops question?!?!?

    Here's my solution, it must have taken me 2 or 3 hours. This is a tough one, I think. When my mind got boggled with nested loops and complex logic, I broke things apart into separate methods...

  • What is the most popular C++ compiler and linker used in the programming industry today?

    Well, the compiler that industries use is of cause Visual Studio from Microsoft. Microsoft offers free Express edition for personal and student use.

    ...
  •  

    Categories--Copyright/IP Policy--Contact Webmaster