Programming Problems
1. Create a program that displays your name and complete mailing address
formatted in the manner that you would usually see it on the outside of an
envelope. Your program does not need to read any input from the user.
2. Write a program that asks the user to enter his or her name. The program
should respond with a message that says hello to the user, using his or her
name.
3. Write a program that accepts radius (datatype: float) of a circle from the
user. Calculate and display the area and circumference of the circle.
4. Write a program that accepts length and breadth (both float) of a rect-
angle from the user. Calculate and display the area and perimeter of the
rectangle.
5. Write a program to accept the side (datatype: float) of a square from the
user. Calculate and display the area and perimeter of the square.
6. Write a program to accept the temperature (datatype: float) in Fahrenheit
and convert it into Centigrade.
7. Write a program to accept two complex numbers. Perform addition, sub-
traction, and multiplication of these numbers and display the results to
the user.
8. Write a program to accept the name and basic salary (datatype: float) of
an employee. Calculate the dearness allowance as 40% of basic and house
rent allowance as 20% of basic. Display the gross salary to the user. (Hint:
gross salary = basic salary + dearness allowance + house rent allowance)
9. Write a program that reads a positive integer, n, from the user and then
displays the sum of all of the integers from 1 to n. The sum of the first n
positive integers can be computed using the formula:
n(n + 1)
sum =
2
10. Create a program that reads two integers, a and b, from the user. Your
program should compute and display:
• The sum of a and b
1
• The difference when b is subtracted from a
• The product of a and b
• The quotient when a is divided by b
• The remainder when a is divided by b
• The result of ab
11. Demonstrate how to create simple and multi-line strings, and check whether
a string can change after its creation.
12. For a given string ‘Hello World!’, extract the following:
• H W
• o o
• llorld
• !dlroW olleH
• World!
• Hello
13. For the following strings, determine which contain only alphabets, only
digits, alphanumeric, which are in lowercase, and which are in uppercase.
Also check whether str3 begins or ends with the word ‘Now’:
• str1 = ‘Welcome’
• str2 = ‘Hello World!’
• str3 = ‘Now is the best time ever! ’
• str4 = ‘500017’
• str5 = ‘IPhone 6’
14. Accept a sentence from the user. Convert the case of the input into title
case.
15. Write a program that reads an integer from the user. Then your program
should display a message indicating whether the integer is even or odd.
16. Create a program that reads a letter of the alphabet from the user. If the
user enters a, e, i, o, or u then your program should display a message
indicating that the entered letter is a vowel. Otherwise, the program
should display a message that the entered letter is a consonant.
17. The length of a month varies from 28 to 31 days. Create a program that
reads the name of a month from the user as a string. Then your program
should display the number of days in that month. Display ‘28 or 29
days’ for February so that leap years are addressed.
2
18. A triangle can be classified based on the lengths of its sides as equilateral,
isosceles, or scalene. All 3 sides of an equilateral triangle have the same
length. An isosceles triangle has two sides that are the same length, and a
third side that is a different length. If all of the sides have different lengths
then the triangle is scalene. Write a program that reads the lengths of 3
sides of a triangle from the user. Display a message indicating the type of
the triangle.
19. The rules for determining whether or not a year is a leap year are as
follows:
• Any year that is divisible by 400 is a leap year.
• Of the remaining years, any year that is divisible by 100 is not a leap
year.
• Of the remaining years, any year that is divisible by 4 is a leap year.
• All other years are not leap years.
Write a program that reads a year from the user and displays a message
indicating whether or not it is a leap year.
20. Write a program that computes the real roots of a quadratic function.
Your program should begin by prompting the user for the values of a, b,
and c. Then it should display a message indicating the number of real
roots, along with the values of the real roots (if any).