0% found this document useful (0 votes)
2 views

COMPUTER-PROGRAMMING-PRACTICE-QUESTIONS

The document contains a series of programming exercises focused on input handling, conditional statements, operators, and loops in C. It includes tasks such as prompting users for various types of input, performing calculations, and implementing control flow structures. Each section provides specific requirements for writing programs that demonstrate fundamental programming concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

COMPUTER-PROGRAMMING-PRACTICE-QUESTIONS

The document contains a series of programming exercises focused on input handling, conditional statements, operators, and loops in C. It includes tasks such as prompting users for various types of input, performing calculations, and implementing control flow structures. Each section provides specific requirements for writing programs that demonstrate fundamental programming concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

INPUT(SCANF) 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".

Operators (Modulus, etc.) Questions


1. Modulus Check: Write a program to check if a given number is divisible by 5 using
the modulus operator.
2. Arithmetic Operations: Prompt the user for two numbers and display the result of
addition, subtraction, multiplication, and division.
3. Increment and Decrement: Write a program to demonstrate the pre-increment
and post-increment operators using a single integer variable.
4. Compound Assignment: Ask the user for a number and use compound
assignments to increment, decrement, multiply, and divide it by another number.
5. Relational Operators: Prompt the user to enter two integers and check if the first
is greater than, less than, or equal to the second. Uses if statements.
6. Logical AND (&&): Write a program that checks if a user-entered number is both
positive and even. Uses if statements. Display “The condition is true” if true and
“The condition is false” if the condition is false.
7. Logical OR (||): Check if a given number is either negative or divisible by 3.
Display “The condition is true” if true and “The condition is false” if the condition is
false. “
8. Ternary Operator: Use a ternary operator to determine if an entered number is
positive or negative and display the result.
9. Swapping Variables: Use arithmetic operations to swap the values of two variables
without a third variable

Loops (While, Do While, For Loop) Questions


1. Counting with For Loop: Write a program that uses a for loop to print numbers
from 1 to 10.
2. Sum of Numbers with While Loop: Prompt the user to enter numbers repeatedly
and calculate their sum. Stop when the user enters zero.
3. Factorial Calculation (For Loop): Use a for loop to calculate the factorial of a
number entered by the user. Factorial Formula (n * n-1 * n-2… )
4. Counting Down with While Loop: Use a while loop to count down from 10 to 1
and print each number.
5. Do-While for Input Validation: Prompt the user to enter a positive number. Use a
do-while loop to repeat until they enter a valid input.
6. Sum of Even Numbers (For Loop): Write a program that uses a for loop to
calculate the sum of all even numbers from 1 to 50.
7. Multiplication Table (While Loop): Ask the user for a number and use a while
loop to print its multiplication table up to 10.
Example :
N=3
3*1 = 3
3*2 = 6
… 3*10 = 30
8. Reverse Digits (While Loop): Prompt the user to enter a number and use a while
loop to print its digits in reverse order.
9. Infinite Loop Check: Write an infinite while loop and add a break condition when a
specific value is input.
10. Prime Number Check (For Loop): Prompt the user for a number and use a for
loop to check if it is prime.
11. Finding Maximum in a Sequence: Use a loop to prompt the user to enter
numbers one by one, stopping when they enter zero, and then print the largest
number entered.
12. Average of Inputs: Use a do-while loop to keep asking the user for numbers,
adding them up until they enter -1. Then display the average.

You might also like