Skip to content
Ankita Wankhede edited this page Jun 12, 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 :

Clone this wiki locally