answersLogoWhite

0


Best Answer

Divide that number into 2 using modulus division. Modulus division get the remainder of the division. If it has no remainders, then it's an even number. If not, then it's an odd number. Here's a pseudo code of the program.

ALGORITHM ODD_EVEN

INPUT (number)

IF (number MOD 2 == 0) THEN

DISPLAY ("Even")

ELSE

DISPLAY ("Odd")

END IF

END ODD_EVEN

Amendment: You did ask for a BASIC program:

10 INPUT X: IF X = 999 THEN STOP

20 PRINT X;: IF X/2 = INT(X/2) THEN PRINT "EVEN" ELSE PRINT "ODD"

30 GOTO 10

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

In pseudocode:

Given value is an integer...

If the least significant bit of value is set

Then return value * value * value

Else return value * value

To determine if the least significant bit is set or not, use the bitwise AND operator. The least significant bit is 0x1, thus value AND 0x1 returns 0x1 when the bit is set, or 0x0 when the bit is not set. However, you need to be careful with signed integers because some architectures use ones complement notation while others use twos complement. With ones complement, a negative value inverts all the bits of the equivalent positive value whereas twos complement inverts the bits and then adds one. Twos complement is more common but if you're not sure of the architecture's representation of signed values or simply want your code to be portable regardless of the representation, then use the MOD (modus) operator to find the remainder after dividing by 0x2. If the result is 0x1, then the value is odd, regardless of its sign. This is less efficient than bitwise AND but if you're certain the architecture is ones complement, then all positive odd values have the least significant bit set while all negative odd values do not (including -0 which is binary 11111110 in ones complement notation). With twos complement, however, all odd values always have the least significant bit set regardless of the sign, and zero is always represented as binary 00000000 (there is no -0 in twos complement notation).

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a basic program find whether number is even or odd if even display its square and if odd display its cube?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the highest square number on a calculator?

It depends on the type of calculator you have. If you have a 8-digit calculator, the largest square number you can display is 99,980,001. If you have a 10-digit calculator, the largest square number you can display is 9,999,800,001. With a TI-84, you can display 9.999999999e99 (which is actually rounded).


How do you check whether a number is a square number?

if it's square root is an integer, it is a square number.


How can I tell whether a number is a square number?

You can tell whether a number is a square number by looking at the last digit. A perfect square number ends with either 1, 4, 5, 6, 9 or 00.


Program to find square and cube of a number?

square and cube caculator


Is 2002 a square number?

Try it out. Take the square root on a calculator, and see whether you get a whole number.


Is 177 a square number?

If your question is whether or not 177 has a square root which is an integer, then no.


How do you display a square root symbol using word pad?

WordPad is not meant to handle the typesetting and display of mathematical expressions. You can use this radical symbol: √ to display simple square roots, but you can't extend the mark above the thing you're taking the square root of. To display more complex expressions, you need a program like MathType, which is specifically designed to typeset math.


What is the fewest number of figures you would have to draw to display a square a rectangle a parallelogram and a trapezoid?

Two, a square and a trapezoid. A square is a rectangle and a parallelogram.


How can you tell whether a square root of a whole number is rational or irrational?

If the whole number is a perfect square, its square root is rational. If not, it's not.


What is the answer to 13 on escape?

Click the numbers to display "453" (the number of sides to square, pentagon, triangle).


Write the program that will ask the user to enter a number of per side of a square and display its outline?

#include<stdio.h> int main() { int side,area of square; print f("Enter the length of side\n"); scan f("%d",&side); area of square=side*side; print f(the area of square is %d\n"area of square); return 0; }


What is the Answer to level 13 on escape?

Click the numbers to display "453" (the number of sides to square, pentagon, triangle).