C
PSUC Practice Arena
🏋️ Practice Arena

C Programming Practice Questions

Sharpen your C programming skills with 150+ curated practice problems organized by topic. Each question comes with a helpful hint — try solving it first, then reveal the hint if you get stuck!

📝 150+ Questions
🧩 10 Modules
💡 Hints Included
🔎

No questions matched your search. Try different keywords!

If Statements
Control Structures — Conditional Logic
18 Questions
▾
Q1
Write a program to find the largest of three numbers.
Compare the first number with the other two, then determine whether it is the largest.
Q2
Write a program to find the smallest of three numbers.
Use relational operators and nested/combined if conditions.
Q3
Write a program to check whether a given number is positive, negative, or zero.
Check n > 0, then n < 0, otherwise it must be zero.
Q4
Write a program to check whether a given number is divisible by both 5 and 11.
Use the % operator and combine two conditions using &&.
Q5
Write a program to check whether a given number is a three-digit number or not.
A positive three-digit number lies between 100 and 999. Also consider negative numbers if required.
Q6
Write a program to find the absolute value of a number without using the library function abs().
If the number is negative, multiply it by -1.
Q7
Write a program to find the largest among three numbers without using the logical AND (&&) operator.
Use nested if-else statements.
Q8
Write a program to check whether three given numbers can form an arithmetic progression.
One number must be the middle term. Check whether 2 × middle = first + third for the possible arrangements.
Q9
Write a program to check whether a given character is an uppercase letter, lowercase letter, digit, or special character.
Compare the character with ASCII ranges such as 'A'-'Z', 'a'-'z', and '0'-'9'.
Q10
Write a program to check whether a given character is an alphabet or not.
Check whether it lies between 'A' and 'Z' OR between 'a' and 'z'.
Q11
Write a program to check whether a person is eligible to vote based on age.
Compare the age with the minimum voting age specified in the question.
Q12
Write a program to calculate electricity bill based on units consumed using different slabs.
Use an if-else-if ladder to apply different rates to different ranges of units.
Q13
Write a program to calculate an employee's bonus based on years of service.
Define different bonus percentages for different ranges of service years and use an if-else-if ladder.
Q14
Write a program to calculate the discount on a purchase based on the total amount.
Use different discount percentages for different purchase-amount ranges.
Q15
Write a program to determine whether a student has passed or failed in three subjects.
Check the minimum marks in each subject, not just the total marks.
Q16
Write a program to calculate a student's division based on percentage. (>= 60 → First, >= 50 → Second, >= 40 → Third, otherwise Fail)
Check the highest range first using an if-else-if ladder.
Q17
Write a program to check whether three given angles can form a triangle and determine the type of triangle from its three sides (Equilateral, Isosceles, or Scalene).
The three angles must have a sum of 180°, and each angle must be > 0°. First verify that the three sides can form a triangle, then compare the sides.
Q18
Write a program to calculate income tax based on annual income using different tax slabs.
Use an if-else-if ladder. Clearly define the income ranges and corresponding tax rates before writing the conditions.
Switch Case
Control Structures — Menu-Driven Programs
20 Questions
▾
Q1
Write a program to display the name of a month based on its number (1–12).
Use the month number as the switch expression and create cases from 1 to 12.
Q2
Write a program to display the number of days in a given month.
Group months having the same number of days using multiple case labels.
Q3
Write a program to convert a number (1–5) into its corresponding Roman numeral.
Use switch cases for 1, 2, 3, 4, and 5.
Q4
Write a program to display the corresponding season based on a month number. (e.g., 12, 1, 2 → Winter)
Multiple month values can be handled by placing multiple case labels before one statement.
Q5
Write a program to perform temperature conversion: (1) Celsius to Fahrenheit (2) Fahrenheit to Celsius.
Use separate cases for each conversion formula.
Q6
Write a program to convert distance: Km↔Metres, Metres↔Centimetres.
Each conversion can be implemented as a separate case.
Q7
Write a program to convert weight: Kg↔Grams, Kg→Pounds.
Use the selected conversion as the switch expression.
Q8
Write a program to calculate the perimeter of a square, rectangle, or circle based on the user's choice.
Use a different case for each shape and ask only for the required dimensions.
Q9
Write a program to calculate the volume of a cube, cuboid, or cylinder based on the user's choice.
Each shape has a different formula; put each formula inside its corresponding case.
Q10
Write a program to determine whether a number is positive, negative, or zero using switch-case.
Since switch cannot directly compare ranges, first convert the number into a category such as 1, -1, or 0, then use switch.
Q11
Write a program to check whether a given character is a vowel using switch-case.
Create cases for a, e, i, o, u and also consider uppercase letters.
Q12
Write a program to display the type of traffic signal: R → Stop, Y → Ready/Wait, G → Go.
Use the character itself as the switch expression.
Q13
Write a program to display the corresponding number of a month from its name (January → 1, etc.).
Use a character/string comparison approach carefully; standard C switch works directly with characters, not strings.
Q14
Write a simple menu-driven unit converter (Length, Weight, Temperature, Time).
Use an outer switch for the category and perform the selected conversion inside each case.
Q15
Write a program to calculate the area of different quadrilaterals (Square, Rectangle, Parallelogram, Trapezium).
Use separate cases and apply the appropriate area formula.
Q16
Write a program to display the number of days in a year (Normal Year vs Leap Year).
Use switch to select the type of year and display 365 or 366.
Q17
Write a menu for mathematical operations: Square, Cube, Square root, Absolute value.
Use switch to select the operation. Use appropriate functions from math.h where required.
Q18
Write a program to convert a number between Decimal → Binary, Octal, Hexadecimal.
Use switch to select the conversion. The actual conversion can be implemented using division/remainder logic.
Q19
Write a program to calculate salary components based on employee category (Manager, Developer, Accountant, Clerk).
Use switch to assign different allowances or percentages to each employee category.
Q20
Write a menu-driven program for a simple banking system (Check Balance, Deposit, Withdraw, Exit).
Use switch for the menu. For withdrawal, check whether the requested amount is less than or equal to the available balance.
Loops
Control Structures — for, while, do-while
20 Questions
▾
Q1
Write a program to find the factorial of a given number.
Start with fact = 1 and multiply it by every integer from 1 to n.
Q2
Write a program to find the sum of digits of a given number.
Extract the last digit using % 10, add it to the sum, and remove it using / 10.
Q3
Write a program to count the number of digits in a given number.
Repeatedly divide the number by 10 and increment a counter.
Q4
Write a program to check whether a given number is a palindrome or not.
Reverse the number and compare the reversed number with the original number.
Q5
Write a program to find the GCD (HCF) of two given numbers.
Repeatedly divide the larger number by the smaller number and use the remainder.
Q6
Write a program to find the LCM of two given numbers.
Start from the larger number and keep checking numbers until one is divisible by both numbers.
Q7
Write a program to generate the Fibonacci series up to n terms.
Maintain three variables representing the previous two terms and their sum.
Q8
Write a program to print the multiplication table of a given number up to 10.
Use a loop from 1 to 10 and multiply the number by the loop counter.
Q9
Write a program to calculate the sum of the first n natural numbers using a loop.
Initialize sum = 0 and add each number from 1 through n.
Q10
Write a program to calculate the sum of all even numbers between 1 and n.
Traverse from 1 to n and add a number only when number % 2 == 0.
Q11
Write a program to calculate the sum of all odd numbers between 1 and n.
Check number % 2 != 0 before adding it to the sum.
Q12
Write a program to print all prime numbers between two given numbers.
For every number in the range, check whether it has any divisor other than 1 and itself.
Q13
Write a program to print all factors of a given number.
Traverse from 1 to n and print a number whenever n % i == 0.
Q14
Write a program to find the sum of all factors of a given number.
Whenever i divides n exactly, add i to the sum.
Q15
Write a program to check whether a number is a perfect number or not.
Find the sum of all positive factors excluding the number itself and compare it with the original number.
Q16
Write a program to check whether a number is a strong number or not. (Example: 145 = 1! + 4! + 5!)
Extract each digit, calculate its factorial, and add the factorials.
Q17
Write a program to print a right-angled triangle star pattern (* pattern).
Use an outer loop for rows and an inner loop to print the required number of stars.
Q18
Write a program to print a number pattern (1, 12, 123, 1234, 12345).
The outer loop controls the rows, while the inner loop prints numbers from 1 to the current row number.
Q19
Write a program to calculate the power x^n without using the pow() function.
Start with result = 1 and multiply it by x, n times.
Q20
Write a program to print the first n terms of the series: 1, 2, 4, 8, 16, 32, ...
Start with term = 1; after printing each term, multiply it by 2.
Nested Loops & Patterns
Advanced Patterns, Pascal's Triangle, Matrices
20 Questions
▾
Q1
Print a Hollow Square Pattern using * for n rows and columns.
***** * * * * * * *****
Use nested loops. Print * when the current row/column is on the boundary.
Q2
Print a Hollow Right-Angled Triangle.
Print * for the first column, last column of each row, and last row.
Q3
Print an Inverted Number Triangle (12345, 1234, 123, 12, 1).
Outer loop controls rows; inner loop runs from 1 to n - row + 1.
Q4
Print a Palindromic Number Pyramid (1, 121, 12321, ...).
Use one loop for spaces, one for increasing numbers, and one for decreasing numbers.
Q5
Print Floyd's Triangle with Even Numbers.
2 4 6 8 10 12 14 16 18 20
Maintain a separate variable initialized to 2 and increase it by 2 after every print.
Q6
Print a Binary Triangle (alternating 0s and 1s).
Use (row + column) % 2 to determine whether to print 0 or 1.
Q7
Print a Diamond Pattern using *.
Divide the pattern into an increasing upper half and decreasing lower half.
Q8
Print a Hollow Diamond pattern.
Combine spaces and boundary conditions for the two halves of the diamond.
Q9
Print a Butterfly Pattern.
Each row contains two groups of stars separated by decreasing/increasing spaces.
Q10
Print a Number Pyramid (row number repeated 2*i-1 times).
Number of stars/numbers in row i is 2*i-1.
Q11
Print Pascal's Triangle for n rows.
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Each element can be calculated using: value = value * (row - column) / (column + 1).
Q12
Print Multiplication Tables in Grid Form (1 to n, values 1 to k).
Outer loop represents the table number; inner loop represents the multiplier.
Q13
Find All Prime Numbers in a Matrix.
Use nested loops to traverse the matrix and another loop to check whether each element is prime.
Q14
Find the Sum of Each Row and Column of a Matrix.
Use nested loops for traversal. Maintain separate sums for rows and columns.
Q15
Find the Transpose of a Matrix.
If the original element is a[i][j], its transpose is stored at a[j][i].
Q16
Check Whether a Matrix is Symmetric.
A matrix is symmetric if a[i][j] == a[j][i] for all valid i and j.
Q17
Find the Sum of Both Diagonals of a Matrix.
Primary diagonal: i == j; secondary diagonal: i + j == n - 1. Be careful not to count the center element twice.
Q18
Multiply Two Matrices using nested loops.
Use three nested loops: one for rows of the first matrix, one for columns of the second, and one for calculating the sum of products.
Q19
Find the Saddle Point of a Matrix (minimum in its row but maximum in its column).
For every element, first determine the minimum value in its row and then check whether it is maximum in its column.
Q20
Print the elements of a matrix in Spiral Order.
Maintain four boundaries: top, bottom, left, and right, and process one boundary at a time.
1-D Arrays
Searching, Sorting, Rotation, Subarrays
20 Questions
▾
Q1
Write a program to find the second largest element in an array without sorting the array.
Maintain two variables for the largest and second-largest values.
Q2
Write a program to find the second smallest element in an array without sorting.
Maintain smallest and secondSmallest while traversing the array.
Q3
Write a program to remove duplicate values from an array and display only unique elements.
For every element, check whether it has already appeared before.
Q4
Write a program to display how many times each element occurs in an array.
Compare one element with all other elements and keep track of already-counted values.
Q5
An array contains numbers from 1 to n, with one number missing. Write a program to find it.
Calculate the expected sum 1 + 2 + ... + n and subtract the array's sum.
Q6
Write a program to place all even numbers before odd numbers in an array.
Use a second array, or use two positions/indexes to rearrange the elements.
Q7
Write a program to rotate an array left by K positions.
Save the first k elements, shift the remaining elements left, then place the saved elements at the end.
Q8
Write a program to rotate an array right by K positions.
Save the last k elements, shift the remaining elements right, then place the saved elements at the beginning.
Q9
Write a program to find all pairs in an array whose sum is equal to a given target.
Use two nested loops and check arr[i] + arr[j] == target.
Q10
Write a program to merge two sorted arrays into one sorted array.
Maintain one index for each array and repeatedly select the smaller element.
Q11
Write a program to move every 0 to the end of an array while preserving the order of non-zero elements.
Keep an index for the next position where a non-zero element should be placed.
Q12
Write a program to find leaders in an array. An element is a leader if every element to its right is smaller.
Start from the right side and maintain the maximum element seen so far.
Q13
Write a program to find an index where the sum of elements on the left equals the sum on the right.
First calculate the total sum, then maintain a running left sum while traversing.
Q14
Write a program to find the maximum arr[j] - arr[i] where j > i.
Keep track of the smallest element seen so far and compare the current difference.
Q15
Given an array containing only 0 and 1, write a program to find the longest sequence of consecutive 1s.
Maintain currentCount and maxCount; reset the current count whenever you encounter 0.
Q16
Write a program to find an element occurring more than n/2 times in an array.
You can count frequencies, or investigate the Boyer-Moore Majority Vote idea.
Q17
Write a program to find elements common to both arrays without printing duplicates.
For each element of the first array, search for it in the second array and make sure it hasn't already been printed.
Q18
Write a program to combine two arrays while avoiding duplicate elements.
Add elements from the first array, then add elements from the second array only if they are not already present.
Q19
Write a program to find the contiguous subarray having the maximum sum.
Try maintaining a running sum and a maximum sum. Think about what should happen when the running sum becomes negative.
Q20
An array contains numbers in a specified range, with one number repeated. Write a program to find the repeated number.
Compare each element with the other elements, or use a frequency/counting approach.
2-D Arrays
Matrices — Operations, Sorting, Rotation
20 Questions
▾
Q1
Write a program to input an m × n matrix and find the sum of all its elements.
Use nested loops to traverse every element and maintain a sum variable.
Q2
Write a program to find the largest and smallest elements in a given matrix.
Initialize max and min with the first element and compare every remaining element.
Q3
Write a program to count the number of positive, negative, and zero elements in a matrix.
Use three counters while traversing the matrix.
Q4
Write a program to find the sum of both diagonals of a square matrix.
Principal diagonal: i == j; secondary diagonal: i + j == n - 1.
Q5
Write a program to find the row number having the maximum sum in a given matrix.
Calculate the sum of each row separately and keep track of the maximum.
Q6
Write a program to find the column number having the minimum sum in a given matrix.
Fix the column in the outer loop and traverse all rows using the inner loop.
Q7
Write a program to input a matrix and interchange any two rows specified by the user.
Use a temporary variable to swap corresponding elements of the two rows.
Q8
Write a program to interchange any two columns of a matrix.
Keep the row fixed and swap the elements at the two selected column positions.
Q9
Write a program to find the transpose of an m × n matrix.
The resulting matrix will have dimensions n × m; store a[i][j] at transpose[j][i].
Q10
Write a program to check whether a square matrix is an identity matrix.
All elements where i == j must be 1, and all other elements must be 0.
Q11
Write a program to check whether a square matrix is upper triangular.
All elements below the principal diagonal (i > j) must be zero.
Q12
Write a program to check whether a square matrix is lower triangular.
All elements above the principal diagonal (i < j) must be zero.
Q13
Write a program to find the largest element in a matrix and print its row and column position.
Whenever a new maximum is found, store both its row index and column index.
Q14
Write a program to count the number of even and odd elements separately for every row.
Reset the even and odd counters for every new row.
Q15
Write a program to sort the elements of every row of a matrix in ascending order.
Apply a simple sorting technique such as bubble sort separately to each row.
Q16
Write a program to sort every column of a matrix in ascending order.
Keep the column fixed and compare elements between different rows.
Q17
Write a program to input two matrices of the same dimensions and calculate their sum.
Add corresponding elements: C[i][j] = A[i][j] + B[i][j].
Q18
Write a program to input two matrices of the same dimensions and calculate their difference.
Subtract corresponding elements: C[i][j] = A[i][j] - B[i][j].
Q19
Write a program to rotate a square matrix by 90° clockwise.
First transpose the matrix, then reverse the elements of each row.
Q20
Write a program to find the frequency of every distinct element in a matrix.
For every element, compare it with all other elements using nested loops. Use another mechanism/array to avoid printing the same element repeatedly.
Strings
Character Arrays — Manipulation & Searching
20 Questions
▾
Q1
Write a program to count the number of vowels, consonants, digits, and special characters in a given string.
Traverse the string character by character and classify each character using ASCII ranges and conditions.
Q2
Write a program to convert all uppercase letters in a string into lowercase.
If a character lies between 'A' and 'Z', add 32 to its ASCII value.
Q3
Toggle the case of each character (HeLLo → hEllO).
Check separately for 'A'-'Z' and 'a'-'z'.
Q4
Count occurrences of each character in a string (e.g., banana → b=1, a=3, n=2).
Use a frequency array of size 256 and ASCII values as indexes.
Q5
Write a program to find the position of the first occurrence of a given character in a string.
Traverse from the beginning and stop when the character matches.
Q6
Write a program to remove every occurrence of a specified character from a string.
Use a second index to overwrite the original string while skipping the selected character.
Q7
Write a program to remove all spaces from a given string.
Copy only non-space characters into the same string.
Q8
Replace spaces with hyphens (C Programming Lab → C-Programming-Lab).
Traverse the string and replace ' ' whenever encountered.
Q9
Write a program to count how many numeric digits are present in a given string.
Check whether each character lies between '0' and '9'.
Q10
Write a program to find and print the longest word in a sentence.
Track the current word length and the longest word's starting position.
Q11
Write a program to find the shortest word in a sentence.
Separate words using spaces and maintain the minimum word length and its position.
Q12
Count occurrences of a word in a sentence (e.g., "C" appears 2 times in "C is easy and C is powerful").
Extract individual words and compare them with the target word using strcmp().
Q13
Write a program to compare two strings without using the predefined strcmp() function.
Compare corresponding characters until a mismatch or '\0' is found.
Q14
Write a program to copy the contents of one string into another without using strcpy().
Copy characters one by one and add '\0' at the end.
Q15
Write a program to concatenate two strings without using the predefined strcat() function.
First find the end of the first string, then copy the second string from that position.
Q16
Remove duplicate characters from a string (programming → progamin).
For each character, check whether it has already appeared in the resulting string.
Q17
Check whether two strings are anagrams (listen ↔ silent).
Count the frequency of each character in both strings and compare the frequency arrays.
Q18
Find the first non-repeating character in a string (swiss → w).
First calculate character frequencies, then scan the string again to find the first character with frequency 1.
Q19
Remove repeated words from a sentence ("C is easy and C is powerful" → "C is easy and powerful").
Store/compare words using a 2-D character array and skip a word if it has already occurred.
Q20
Find and replace a word in a sentence ("I like Java programming" → Find: Java, Replace: C → "I like C programming").
Break the sentence into words, compare each word with the target using strcmp(), and construct the resulting sentence.
Functions
Modular Programming — Reusable Code
20 Questions
▾
Q1
Write a program to find the smallest number among a given set of numbers using a function Min().
Pass the array and its size to the function and return the minimum value.
Q2
Write a program to calculate x^n using a function without using pow().
Use a loop inside the function and multiply x by itself n times.
Q3
Write a function Palindrome() that checks whether a given number is a palindrome.
Reverse the number inside the function and compare it with the original number.
Q4
Write a program to calculate the sum of digits of a number using a function SumDigits().
Extract digits using % 10 and repeatedly divide the number by 10.
Q5
Write a function Reverse() that returns the reverse of a given integer.
Build the reversed number using reverse = reverse * 10 + digit.
Q6
Write a program to find both GCD and LCM of two numbers using separate functions.
Create GCD() and LCM() functions. Use LCM = (a / GCD) * b.
Q7
Write a program using a function Armstrong() to check whether a given number is an Armstrong number.
Count the digits first, then calculate the sum of each digit raised to the number of digits.
Q8
Write a program to input an array and calculate the sum of its elements using a function.
Pass the array and its size to Sum().
Q9
Write a program to calculate the average of elements of an array using a function.
Create a function that returns the sum, then divide by the array size.
Q10
Write a program to count the number of even and odd elements in an array using functions.
Create separate functions such as CountEven() and CountOdd().
Q11
Write a program to find the second largest element in an array using a function without sorting the array.
Maintain largest and secondLargest while traversing the array.
Q12
Write a program to sort an array in ascending order using a function Sort().
Pass the array to the function and implement bubble sort or selection sort.
Q13
Write a program to search for an element in an array using a function Search().
Return the index of the element if found; otherwise return -1.
Q14
Write a program to count how many prime numbers are present in an array using a function IsPrime().
Reuse IsPrime() for every array element and increment a counter when it returns true.
Q15
Write a program to find the largest element in a 2-D matrix using a function.
Pass the matrix along with its row and column sizes to the function.
Q16
Write a program to add two matrices using a function AddMatrix().
Pass both matrices, the result matrix, and their dimensions to the function.
Q17
Write a program to find the length of a string without using strlen(), using a function Length().
Traverse the string until '\0' and return the character count.
Q18
Write a program to count the number of vowels in a string using a function CountVowels().
Traverse the string and check each character against a, e, i, o, u and their uppercase forms.
Q19
Write a program to convert a decimal number into its binary representation using a function.
Repeatedly divide the number by 2 and store the remainders. Print them in reverse order.
Q20
Write a menu-driven calculator program that performs addition, subtraction, multiplication, division, and modulus using separate functions.
Create separate functions such as Add(), Subtract(), Multiply(), Divide(), and Modulus(), and call the appropriate function based on the user's choice.
Pointers
Pointer Arithmetic, Arrays & Strings via Pointers
20 Questions
▾
Q1
Write a program to swap the values of two integers using pointers.
Pass the addresses of both variables to a Swap() function and use a temporary variable.
Q2
Write a program to find the largest element in an array using pointer arithmetic.
Start with p = arr and access elements using *(p + i).
Q3
Write a program to find the smallest element in an array using a pointer.
Traverse the array by incrementing the pointer.
Q4
Write a program to reverse the elements of an array using pointers.
Use two pointers, one pointing to the first element and another to the last element, and swap their values.
Q5
Write a program to copy all elements of one array into another using pointers.
Use source and destination pointers and increment both after every assignment.
Q6
Write a program to check whether two arrays contain the same elements in the same order using pointers.
Compare *(p1+i) with *(p2+i) for every index.
Q7
Write a program to count the number of even and odd elements in an array using pointer arithmetic.
Traverse using a pointer and check *p % 2.
Q8
Write a program to calculate the average of all elements in an array using a pointer.
Use a pointer to calculate the sum, then divide by the number of elements.
Q9
Write a program to find the second largest element in an array without sorting, using pointers.
Maintain largest and secondLargest while traversing through *p.
Q10
Write a program to search for a given element in an array using a pointer and return its position.
Compare the value pointed to by p with the target during traversal.
Q11
Write a program to count the number of vowels in a string using a character pointer.
Traverse until *p == '\0' and check each character for a, e, i, o, u.
Q12
Write a program to reverse a string using pointers without using strrev().
Use one pointer at the beginning and another at the end of the string and swap characters.
Q13
Write a program to copy one string into another using pointers without using strcpy().
Copy characters using *dest = *src until the null character is reached.
Q14
Write a program to compare two strings using pointers without using strcmp().
Traverse both strings simultaneously and compare the characters pointed to by the two pointers.
Q15
Write a program to concatenate two strings using pointers without using strcat().
Move the pointer to the '\0' of the first string, then copy the second string from there.
Q16
Write a program to find both the first and last occurrence of a given character in a string using pointers.
Maintain pointers/positions whenever the target character is encountered.
Q17
Write a program to find the length of the longest word in a sentence using a character pointer.
Traverse the string and maintain the current word length and maximum word length.
Q18
Write a program to add two matrices using pointers instead of normal array indexing.
Treat the 2-D arrays as contiguous memory and access elements using pointer arithmetic.
Q19
Write a program to find the sum of the principal diagonal elements of a square matrix using pointers.
For an n × n matrix, the diagonal elements are at offsets i*n + i.
Q20
Write your own function mystrlen() to calculate the length of a string using only a pointer, without using strlen() or array indexing.
Start a pointer at the first character and increment it until '\0'; the number of increments is the length.
Structures
User-Defined Types — Records & Nested Structures
20 Questions
▾
Q1
Define a structure Book containing book ID, title, author name, and price. Read details of one book and display them.
Use a structure variable and access members using the . operator.
Q2
Create an array of Book structures for N books. Display the details of the book having the highest price.
Maintain the index of the book with maximum price.
Q3
Create a Student structure containing roll number, name, and marks in 3 subjects. Find and display the student with the highest average.
Calculate average for each structure and compare it with the current maximum.
Q4
Store roll number, name, and marks in 5 subjects. Calculate total, percentage, and result (Pass/Fail) for each student.
Add all subject marks and use percentage to determine the result.
Q5
Define an Employee structure containing employee ID, name, department, and salary. Read N employees and display the employee receiving the highest salary.
Compare the salary member of each structure.
Q6
Store employee ID, name, and salary for N employees. Sort and display employees in decreasing order of salary.
Swap complete structure variables during sorting.
Q7
Create an array of student structures containing roll number and name. Sort the students alphabetically by name.
Use strcmp() to compare the name members.
Q8
Store details of N employees and search for an employee using employee ID. Display all details if found.
Compare the entered ID with emp[i].id.
Q9
Store roll number, name, and marks of N students. Calculate the average marks and display the students whose marks are above average.
First calculate the overall average, then traverse the array again.
Q10
Define a structure Product containing product ID, name, quantity, and price. Calculate and display the total inventory value.
For each product, value = quantity × price.
Q11
Store details of N products and find the product having the minimum quantity available.
Compare the quantity member of each structure.
Q12
Define a Customer structure containing customer ID, name, units purchased, and price per unit. Calculate and display the total bill for each customer.
total = units × price_per_unit.
Q13
Define a structure Date containing day, month, and year. Read two dates and determine which date is earlier.
Compare year first, then month, then day.
Q14
Define a Date structure for date of birth and another for the current date. Calculate the person's approximate age in years.
Subtract birth year from current year and adjust if the birthday has not occurred yet.
Q15
Define a structure Time containing hours, minutes, and seconds. Read two times and calculate their sum.
Add seconds first, carry extra seconds to minutes, then do the same for minutes.
Q16
Define a Time structure and find the difference between two given times.
Convert both times into total seconds, subtract, then convert the result back to hours, minutes, and seconds.
Q17
Define a structure Complex containing real and imaginary parts. Read two complex numbers and perform addition and subtraction.
Add/subtract real parts separately and imaginary parts separately.
Q18
Define a structure Distance containing kilometers and meters. Read two distances and calculate their sum.
Add meters first; convert every 1000 meters into 1 kilometer.
Q19
Define a Student structure containing roll number, name, and an Address structure with city, state, and PIN code. Read and display complete student details.
Access nested members like student.address.city.
Q20
Define an Employee structure containing ID, name, department, and salary. Read N employees and calculate the total and average salary for each department.
Group employees by department and maintain separate total salary and employee count for each department.