Conditional Structures

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Conditional Structures

1. Write a program that prompts the user to input a number and display if the number

is even or odd.

2. Write a program that takes an age as input and determines whether a person
is eligible to vote. If the age is 18 or above, print "You are eligible to vote." Otherwise,

print "You are not eligible to vote yet.".

3. Write a program that prompts the user to input two integers and outputs the largest.

4. Write a program that prompts the user to enter a number and determines whether it
is positive, negative, or zero. The program should print "Positive" if the number is

greater than 0, "Negative" if the number is less than 0, and "Zero" if the number is 0.

5. Write a program that prompts the user to enter their age and prints the
corresponding age group. The program should use the following age groups:

0-12: Child

13-19: Teenager

20-59: Adult

60 and above: Senior Citizen

6. Write a program that prompts the user to input a number from 1 to 7. The program
should display the corresponding day for the given number. For example, if the user

types 1, the output should be Sunday. If the user types 7, the output should be

Saturday. If the number is not between 1 to 7 user should get error message as shown

in sample output.
7. Write a program that prompts the user to enter their weight (in kilograms) and height
(in meters). The program should calculate the Body Mass Index (BMI) using the formula:

BMI = weight / (height * height). The program should then classify the BMI into one of

the following categories:

less than 18.5 - Underweight

BMI between 18.5 and 24.9 - Normal weight

BMI between 25 and 29.9 - Overweight

BMI 30 or greater – Obesity

8. The marks obtained by a student in 3 different subjects are input by the user. Your
program should calculate the average of subjects and display the grade. The student

gets a grade as per the following rules:

Average Grade

90-100 A

80-89 B

70-79 C

60-69 D

0-59 F

10. Write a program that prompts the user to enter three numbers and sorts them in
ascending order. The program should print the sorted numbers.

11. Write a program that prompts the user to input three integers and outputs the
largest.

12. Write a program that prompts the user to input a character and determine the
character is vowel or consonant.
13. Write a program that prompts the user to input a year and determine whether the
year is a leap year or not.

Leap Years are any year that can be evenly divided by 4. A year that is evenly divisible by

100 is a leap year only if it is also evenly divisible by 400. Example:

1992 Leap Year

2000 Leap Year

1900 NOT a Leap Year

1995 NOT a Leap Year

14. Write a program that prompts the user to input number of calls and calculate the
monthly telephone bills as per the following rule:

Minimum Rs. 200 for up to 100 calls.

Plus Rs. 0.60 per call for next 50 calls.

Plus Rs. 0.50 per call for next 50 calls.

Plus Rs. 0.40 per call for any call beyond 200 calls.

You might also like