COMPUTER-PROGRAMMING-PRACTICE-QUESTIONS
COMPUTER-PROGRAMMING-PRACTICE-QUESTIONS
1. Basic Input: Write a program that prompts the user to enter their age and uses
scanf to store it in a variable. Display the entered age by “Your age is __” in the
console using printf.
2. String Input: Prompt the user to enter their first name, store it using scanf, and
display it by “The User’s First Name is: ____” in the console using printf.
3. Multiple Inputs: Write a program that asks the user to enter two integers in a
single line and then calculates their sum. Then display it in the console using printf
“The sum of the two numbers is ___”
4. Float Input: Use scanf to prompt the user to enter their height in meters, store it in
a float variable, and print it back.
5. Character Input: Write a program that asks the user to enter a single character and
then displays that character.
6. Reading a Double: Prompt the user for a double value representing the value of pi.
Store it using scanf and print it.
7. Reading Multiple Types: Ask the user to enter an integer and a float in one line
and then display both.
8. Reading Date Input: Write a program that prompts the user to enter a date and
uses the format `dd-mm-yyyy` to display it in the console. This uses `scanf` to store it in
three integer variables, and then displays each part of the date separately (day, month,
year).
9. Reading Multiple Floats: Prompt the user to enter three decimal numbers (floats)
separated by spaces. Use `scanf` to store each value in a separate variable and print
them all.
10. Reading Complex Format: Ask the user to enter a time in the format `hh:mm:ss`
(hours, minutes, seconds). Use `scanf` to parse each part into separate integer variables
and then display them in the same format.
Conditional Statements (If, Else, Else If, Switch) Questions
1. Basic If: Write a program that prompts the user to enter an integer. Use an if
statement to print "Even" if the number is even.
2. If-Else: Write a program that prompts the user for a grade and prints "Pass" if it’s 50
or above; otherwise, print "Fail".
3. Nested If: Ask the user to enter a number. If the number is positive, check if it’s
even or odd and display the result.
4. Else if: Write a program that prompts the user for their age and categorizes them as
"Child" (0-12), "Teen" (13-19), or "Adult" (20+).
5. Switch Statement: Create a menu-based program using switch that prompts the
user to enter a choice (1 for Addition, 2 for Subtraction) and performs the
corresponding operation.
6. Boolean Check with If-Else: Write a program that asks the user to enter a
temperature in Celsius and displays "Hot" if it’s above 30, "Cold" if it’s below 15, and
"Moderate" otherwise.
7. Temperature Readings: Prompt the user to enter temperatures for three different
days, store them as floats, and display each with a label for the day..
8. Leap Year Check: Use an if-else statement to check if a year entered by the user is
a leap year.
9. Calculator with Switch: Use switch to perform addition, subtraction,
multiplication, or division based on the user’s choice.
10. Login Check: Prompt the user to enter a password. Use if-else to check if it
matches a preset password and print "Access Granted" or "Access Denied".