Problem Solving Using C
Sample Programming Questions
Conditional Branching:
1. Check for Even or Odd
Write a program that takes an integer as input and checks if it is even or odd using an
if condition.
2. Check for Positive, Negative, or Zero
Write a program that takes an integer and checks if it is positive, negative, or zero
using if conditions.
3. Find the Largest of Two Numbers
Write a program that takes two integers as input and prints the larger one using an if
condition.
4. Check Eligibility to Vote
Write a program that takes the age of a person as input and checks if they are eligible
to vote (age 18 or above).
5. Grade Calculation Based on Score
Write a program that takes a student’s score as input and displays a grade based on
the score:
90 and above: Grade A
80 to 89: Grade B
70 to 79: Grade C
Below 70: Grade D
6. Simple Calculator Using if Conditions
Write a program that takes two numbers and an operator (+, -, *, /) as input, then
performs the corresponding arithmetic operation.
7. Check for Leap Year
Write a program that takes a year as input and checks if it is a leap year using if
conditions.
8. Check if a Number is Divisible by Both 5 and 11
Write a program that takes an integer as input and checks if it is divisible by both 5
and 11.
9. Check if Number is Three-Digit
Write a program that takes an integer and checks if it is a three-digit number using an
if condition.
10. Check if Number Ends with 5
Write a program that takes an integer and checks if it ends in the digit 5 using if
conditions.
1 Prof. Swetanjali Maharana
11. Check for Uppercase or Lowercase Character
Write a program that takes a single character as input and checks if it is an uppercase
or lowercase letter.
12. Find the Largest of Three Numbers
Write a program that takes three numbers as input and finds the largest among them
using if conditions.
13. Check if Number is Prime
Write a program that takes an integer and checks if it is a prime number using if
conditions and loops.
14. Identify if Character is Vowel or Consonant
Write a program that takes a character as input and checks if it is a vowel or
consonant.
15. Check if Year is a Century Year
Write a program that takes a year as input and checks if it is a century year (divisible
by 100) using if conditions.
16. Determine if Character is a Digit
Write a program that takes a character as input and checks if it is a digit (0–9).
17. Find the Middle of Three Numbers
Write a program that takes three numbers as input and finds the middle number
using if conditions.
18. Find the Smallest Digit in a Number
Write a program that takes a multi-digit number as input and finds the smallest digit
using a loop and if conditions.
19. Electricity Bill Calculation
Write a program to calculate an electricity bill based on the following rates:
Up to 100 units: $0.50 per unit
101 to 200 units: $0.75 per unit
Above 200 units: $1.20 per unit
20. Simple Interest Calculation with Condition on Principal
Write a program that calculates the simple interest given P, R, and T. If P is less than
1000, increase P by 10% before calculating interest.
Looping:
1. Print Multiplication Table
Write a program that takes an integer as input and prints its multiplication table up
to 10 using a for loop.
2. Sum of First N Natural Numbers
Write a program that takes an integer N and calculates the sum of the first N natural
numbers using a while loop.
3. Count Digits in a Number
Write a program that takes an integer as input and counts the number of digits using
a while loop.
2 Prof. Swetanjali Maharana
4. Reverse a Number
Write a program that takes an integer and reverses its digits using a while loop.
5. Check if Number is Prime
Write a program that takes an integer and checks if it is a prime number using a for
loop.
6. Print Even and Odd Numbers up to N
Write a program that takes an integer N and prints all even and odd numbers up to N
separately using a for loop.
7. Calculate Factorial
Write a program that takes an integer N and calculates its factorial using a for loop.
8. Find GCD of Two Numbers
Write a program that takes two integers and calculates their Greatest Common
Divisor (GCD) using a while loop.
9. Find Sum of Digits
Write a program that takes an integer and calculates the sum of its digits using a
loop.
10. Check if Number is Palindrome
Write a program to check if a given integer is a palindrome (reads the same forwards
and backwards).
11. Find Smallest Digit in a Number
Write a program that takes an integer and finds its smallest digit using a loop.
12. Find Largest Digit in a Number
Write a program that takes an integer and finds its largest digit using a loop.
13. Print Fibonacci Sequence up to N Terms
Write a program that takes an integer N and prints the first N terms of the Fibonacci
sequence using a loop.
14. Calculate Power without Using pow
Write a program to calculate a^b (a raised to the power b) using a for loop.
15. Find LCM of Two Numbers
Write a program that takes two integers and calculates their Least Common Multiple
(LCM) using a loop.
16. Check if Number is Armstrong
Write a program that takes a three-digit integer and checks if it is an Armstrong
number.
17. Sum of Cubes of Digits
Write a program that takes an integer and calculates the sum of the cubes of its
digits using a loop.
18. Display Divisors of a Number
Write a program that takes an integer and prints all of its divisors using a for loop.
19. Check for Perfect Number
Write a program that takes an integer and checks if it is a perfect number. A perfect
number is one whose divisors (excluding itself) sum up to the number itself.
Array:
1. Sum of Array Elements
Write a program to calculate the sum of all elements in an integer array.
3 Prof. Swetanjali Maharana
2. Find Maximum and Minimum
Write a program to find the maximum and minimum elements in an integer array.
3. Reverse an Array
Write a program to reverse the elements of an array without using an additional
array.
4. Count Even and Odd Numbers
Write a program to count the number of even and odd numbers in an array.
5. Search an Element
Write a program to search for a specific element in an array and print its index if
found.
6. Sort an Array
Write a program to sort an array in ascending order using the bubble sort algorithm.
7. Remove Duplicates
Write a program to remove duplicate elements from an array.
8. Merge Two Arrays
Write a program to merge two arrays into a single array.
9. Shift Elements
Write a program to shift all elements of an array to the left by one position. The first
element should move to the end.
10. Matrix Multiplication
Write a program to multiply two 2D arrays (matrices) and display the result.
Function:
1. Calculate Factorial
Write a function to calculate the factorial of a number using recursion.
2. Check Prime Number
Write a function to check whether a given number is prime.
3. Find GCD (Greatest Common Divisor)
Write a function to find the GCD of two numbers using the Euclidean algorithm.
4. Reverse a Number
Write a function to reverse the digits of a given number.
5. Fibonacci Series
Write a function to print the Fibonacci series up to a given number of terms.
6. Check Palindrome
Write a function to check whether a given string or number is a palindrome.
7. Power Calculation
Write a function to calculate the power of a number (base^exponent) using
recursion.
8. Sort an Array
Write a function to sort an array using the selection sort algorithm.
9. Count Vowels in a String
Write a function to count the number of vowels in a given string.
4 Prof. Swetanjali Maharana
10. Check Armstrong Number
Write a function to check whether a given number is an Armstrong number.
11. Sum of Digits
Write a function to calculate the sum of the digits of a given number.
12. Find the Largest Element in an Array
Write a function to find the largest element in an array.
13. Swap Two Numbers
Write a function to swap two numbers using pointers.
14. Check Leap Year
Write a function to check whether a given year is a leap year.
15. Decimal to Binary Conversion
Write a function to convert a decimal number to binary.
16. LCM (Least Common Multiple)
Write a function to calculate the LCM of two numbers.
17. Transpose of a Matrix
Write a function to find the transpose of a given matrix.
18. Count Words in a String
Write a function to count the number of words in a given string.
19. Find Roots of a Quadratic Equation
Write a function to find the roots of a quadratic equation given its coefficients.
Recursion:
1. Factorial of a Number
Write a recursive function to calculate the factorial of a given number.
2. Fibonacci Series
Write a recursive function to print the Fibonacci series up to a given term.
3. Sum of Natural Numbers
Write a recursive function to calculate the sum of the first n natural numbers.
4. Reverse a Number
Write a recursive function to reverse the digits of a given number.
5. Power of a Number
Write a recursive function to calculate base^exponent.
6. Greatest Common Divisor (GCD)
Write a recursive function to find the GCD of two numbers using the Euclidean
algorithm.
7. Check Palindrome (String)
Write a recursive function to check if a string is a palindrome.
8. Sum of Digits
Write a recursive function to calculate the sum of the digits of a number.
Pointer:
1. Swap Two Numbers
Write a function to swap two numbers using pointers.
5 Prof. Swetanjali Maharana
2. Sum of Two Numbers
Write a function to calculate the sum of two numbers using pointers.
3. Reverse an Array
Write a program to reverse an array using pointers.
4. Find the Largest Element in an Array
Write a program to find the largest element in an array using pointers.
5. String Length
Write a function to calculate the length of a string using pointers.
6. Copy a String
Write a function to copy a string from one pointer to another.
7. Count Vowels in a String
Write a function to count the number of vowels in a string using pointers.
8. Dynamic Memory Allocation
Write a program to allocate memory dynamically for an array and find the sum of its
elements.
9. Transpose of a Matrix
Write a program to find the transpose of a matrix using pointers.
10. Pointer to a Function
Write a program to demonstrate the use of a pointer to a function by performing
basic arithmetic operations (addition, subtraction, multiplication, division).
Structure:
1. Student Details
Define a structure for a student containing fields like name, roll number, and marks.
Write a program to input and display the details of a student.
2. Employee Details
Define a structure for an employee with fields like name, ID, and salary. Write a
program to input and display the details of multiple employees.
3. Complex Numbers
Define a structure for a complex number with real and imaginary parts. Write a
program to add two complex numbers.
4. Point Operations
Define a structure for a 2D point with x and y coordinates. Write a program to
calculate the distance between two points.
5. Rectangle Properties
Define a structure for a rectangle with length and breadth. Write a program to
calculate the area and perimeter of a rectangle.
6. Book Details
Define a structure for a book with fields like title, author, and price. Write a program
to input and display the details of multiple books and find the most expensive book.
7. Date Operations
Define a structure for a date with day, month, and year. Write a program to check
whether a given year is a leap year.
6 Prof. Swetanjali Maharana
8. Nested Structures
Define a structure for a student that contains another structure for address (house
number, city, and state). Write a program to input and display the details of a student
with their address.
9. Cricket Player Details
Define a structure for a cricket player with fields like name, matches played, and runs
scored. Write a program to calculate the average runs of all players.
10. Dynamic Memory Allocation with Structures
Define a structure for a product with fields like name, ID, and price. Write a program
to dynamically allocate memory for an array of products and calculate the total price
of all products.
File Handling:
1. Read and Write to a File
Write a program to create a file, write some text into it, and then read and display
the content of the file.
2. Count Characters, Words, and Lines
Write a program to read a text file and count the number of characters, words, and
lines in the file.
3. Copy Content of One File to Another
Write a program to copy the content of one file into another file.
4. Append Text to a File
Write a program to append some text to an existing file.
5. Check if a File Exists
Write a program to check whether a file exists in the current directory.
6. Find the Longest Word in a File
Write a program to find and display the longest word in a text file.
7. Merge Two Files
Write a program to merge the contents of two files into a third file.
8. Reverse File Content
Write a program to reverse the content of a file and save it to another file.
9. Count Frequency of a Word
Write a program to count the frequency of a specific word in a text file.
10. Student Records Management
Write a program to manage student records using file handling. The program should
allow adding, viewing, and searching student details (name, roll number, and marks)
in a file.
7 Prof. Swetanjali Maharana