Skip to content
Ankita Wankhede edited this page Jun 19, 2017 · 9 revisions

PROGRAM 1 : Check whether a number entered by a user is even or odd

In the program, integer entered by the user is stored in variable number.

Then, whether the number is perfectly divisible by 2 or not is checked using modulus operator.

If the number is perfectly divisible by 2, test expression number%2 == 0 evaluates to 1 (true) and the number is even.

However, if the test expression evaluates to 0 (false), the number is odd.

Here is the output :

PROGRAM 2 : Take length and breadth from a user for a rectangle and calculate perimeter for the same Number

In the program, integer entered by the user is stored in variable number.

find the perimeter of a rectangle you have to add the lengths of all the four sides. x is in this case the length of the rectangle while y is the breadth of the rectangle. The perimeter, P, is: P=x+x+y+y P=x+x+y+y P=2x+2y P=2x+2y P=2(x+y)

Here is the output :

3.This is a number guess exercise. First pick a random digit via program i.e 0,1,2,3,4,5,6,7,8,9 Ask the user to guess the digit randomly picked by your program. Then print whether the number guess by the user is perfect or below the random number or above the random number. Also your program should explain the rules of this number guess game to the user

Clone this wiki locally