1. Assign the value 10 to a variable named x and the value 20 to a variable named y.
What
are the values of x and y?
2. Assign the value 7 to a variable num1 and 3 to num2. Write a program to calculate their
sum, difference, product, and quotient.
3. Assign 5 to an integer variable a and 5.5 to a double variable b. Then, print the result of
adding them together.
4. Assign the length and width of a rectangle to two variables and calculate its area.
Example: length = 10, width = 5.
5. Assign values to the principal (P), rate of interest (R), and time (T), and calculate the
simple interest using the formula:
Simple Interest=P×R×T100
Example: P = 1000, R = 5, T = 2.
6. Assign a value to a variable Celsius and convert it to Fahrenheit using the formula:
Fahrenheit=(Celsius×9/5)+32
Example: Celsius = 25.
7. Assign the length and width of a rectangle to two variables and calculate its perimeter.
Formula:
Perimeter=2×(length + width)
Example: length = 12, width = 7.
8. Assign three numbers to variables and calculate their average.
Example: num1 = 15, num2 = 25, num3 = 35.
9. Assign a number to a variable and calculate both its square and cube.
Example: number = 4.
Square=number × number
Cube=number × number × number
10. Distance Calculation (Speed and Time)
Assign values for speed and time to two variables and calculate the distance covered.
Formula:
Distance=speed×time
Example: speed = 60 km/h, time = 3 hours.
11. Convert Minutes to Hours and Minutes
Assign a value to a variable minutes and convert it into hours and remaining minutes.
Example: minutes = 130.
Formula:
hours=minutes/60
remaining minutes=minutes%60
Example: radius = 7.
12. Body Mass Index (BMI)
Assign values to a person’s weight (in kilograms) and height (in meters), then calculate
the BMI using the formula:
BMI=weight/height2
Example: weight = 70 kg, height = 1.75 m.
13. Convert Celsius to Kelvin
Assign a value to a variable celsius and convert it to Kelvin.
Formula:
Kelvin=Celsius+273.15
Example: celsius = 30.
14. Price After Discount
Assign values to price and discount percentage, then calculate the final price after
applying the discount.
Formula:
Discount Amount=price ×discount percentage/100
Final Price=price−Discount Amount
Example: price = 500, discount percentage = 10%.