Basic Arithmetic & Input/Output
Mastering how to handle variables and perform calculations is the first step in any programming language. These problems are language-agnostic and can be solved in C, C++, Java, Python, or any other language.
Examples
1. The Classic "Hello World"
Rating: Newbie | Difficulty: Easy Print "Hello, World!" to the screen.
💡 Hint
Use your language's
standard output function (e.g., printf in C, cout in C++, System.out.println in Java).
2. Sum of Two Numbers
Rating: Newbie | Difficulty: Easy Take two integers as input from the user and print their sum.
💡 Hint
Declare two variables, use an input function (e.g., scanf or Scanner), and print a + b.
3. Temperature Converter (Celsius to Fahrenheit)
Rating: Newbie | Difficulty: Easy
Input temperature in Celsius and convert it to Fahrenheit using the formula: F = (C * 9/5) + 32.
💡 Hint
Use float or double for precision since division is
involved.
4. Area of a Circle
Rating: Beginner | Difficulty: Easy
Input the radius of a circle and calculate its area (πr²). Use 3.14159 for π.
💡 Hint
Area = 3.14159 * radius * radius.
5. Simple Interest Calculator
Rating: Beginner | Difficulty: Easy
Calculate Simple Interest based on input: Principal, Rate, and Time. Formula: SI = (P * R * T) / 100.
💡 Hint
Input three variables and apply the formula directly.
6. Swap Two Numbers (With Third Variable)
Rating: Beginner | Difficulty: Easy Input two numbers and swap their values using a temporary third variable.
💡 Hint
temp = a; a = b; b = temp;
7. Swap Two Numbers (Without Third Variable)
Rating: Intermediate | Difficulty: Medium Swap two numbers without using any extra variables.
💡 Hint
Use addition
and subtraction: a = a + b; b = a - b; a = a - b;
8. Time Converter
Rating: Intermediate | Difficulty: Medium
Input total seconds and convert it into Hours : Minutes : Seconds format.
💡 Hint
Use the modulus operator %. Hours = seconds / 3600, remaining seconds = seconds % 3600.
9. Body Mass Index (BMI)
Rating: Intermediate | Difficulty: Medium
Calculate BMI using weight (kg) and height (meters). Formula: BMI = weight / (height * height).
💡 Hint
Ensure height is taken as a float/double.
10. ASCII Value Finder
Rating: Beginner | Difficulty: Easy Input a character and print its corresponding ASCII integer value.
💡 Hint
In C/C++/Java, you can simply cast a char to an int.
11. Days to Years, Weeks, and Days
Rating: Intermediate | Difficulty: Medium Convert a given number of days into Years, Weeks, and remaining Days. (Assume 1 Year = 365 Days).
💡 Hint
Years = days / 365. Remaining days = days % 365.
12. Compound Interest
Rating: Advanced | Difficulty: Medium
Calculate Compound Interest. Formula: A = P(1 + r/n)^{nt}.
💡 Hint
You
will need a math library for the power function (e.g., pow() in C/C++, Math.pow() in Java).
13. Distance Between Two Points
Rating: Advanced | Difficulty: Medium
Input coordinates (x1, y1) and (x2, y2) and find the distance between them. Formula: `√((x2-x1)²
- (y2-y1)²)`.
💡 Hint
Use sqrt() and pow() functions from your
language's math library.
14. Total and Percentage
Rating: Beginner | Difficulty: Easy Input marks of 5 subjects (out of 100 each). Calculate the Total and the Percentage.
💡 Hint
Percentage = (Total / 500.0) * 100.
15. Volume of a Cylinder
Rating: Pro | Difficulty: Medium
Input radius and height of a cylinder. Calculate the volume. Formula: V = πr²h.
💡 Hint
Volume = 3.14159 * radius * radius * height.