C Programming Practice Problems

Topic-by-topic practice problems plus mixed review and fill-in-the-blank final exam prep: 142 problems in all. For every problem, write your code in the browser and press "Check" to run it with real gcc and see whether it is correct. Hints, solutions and explanations included.

Practice problems by topic (auto-checked in your browser)

142 problems. Write your code and press "Check" to run it with real gcc and see whether it is correct. Listed in learning order.

All problems

1. Variables, operators & I/O

  1. BeginnerThe four arithmetic operations on two integers
  2. BeginnerArea and circumference of a circle
  3. BeginnerCelsius to Fahrenheit
  4. BeginnerDigits of a 3-digit number and its reverse
  5. IntermediateTotal and average of 3 subjects
  6. IntermediateConvert seconds to h:mm:ss
  7. IntermediateBreak an amount into bills and coins
  8. IntermediateCharacter codes and upper/lower case
  9. IntermediateInteger part, fractional part and rounding
  10. AdvancedBMI and standard weight
  11. AdvancedMake a receipt
  12. AdvancedDivision and remainder of negative numbers
  13. AdvancedAdding time

2. if & switch

  1. BeginnerPositive, negative or zero
  2. BeginnerEven or odd
  3. BeginnerThe larger of two numbers
  4. BeginnerScore range check
  5. IntermediateGrading
  6. IntermediateMaximum and minimum of three numbers
  7. IntermediateLeap year check
  8. IntermediateDays in a month (switch)
  9. IntermediateRock-paper-scissors
  10. AdvancedA simple calculator
  11. AdvancedClassifying triangles
  12. AdvancedWhich date comes first

3. for & while loops

  1. BeginnerSum from 1 to N
  2. BeginnerMultiplication table
  3. BeginnerEven numbers up to N
  4. BeginnerFactorial
  5. IntermediateSum of digits
  6. IntermediateSum until 0 is entered
  7. IntermediateList the divisors
  8. IntermediateDraw a right triangle
  9. IntermediateFizzBuzz
  10. AdvancedPrint all primes up to N
  11. AdvancedDraw a pyramid
  12. AdvancedGreatest common divisor and least common multiple
  13. AdvancedThe Collatz problem

4. Arrays

  1. BeginnerPrint in reverse order
  2. BeginnerSum and average
  3. BeginnerPositions of the maximum and minimum
  4. BeginnerDifferences between neighbors
  5. IntermediateSearching for a value
  6. IntermediateValues at or above the average
  7. IntermediateScore histogram
  8. IntermediateThe second largest value
  9. IntermediateRow and column sums (2D array)
  10. AdvancedBubble sort and the number of swaps
  11. AdvancedSelection sort, step by step
  12. AdvancedMatrix multiplication
  13. AdvancedBinary search

5. Strings

  1. BeginnerCount the length of a string
  2. BeginnerPrint character codes
  3. BeginnerSwap upper and lower case
  4. BeginnerCount occurrences of a character
  5. IntermediateReverse a string
  6. IntermediatePalindrome check
  7. IntermediateLetter frequencies
  8. IntermediateSort two words in dictionary order
  9. IntermediateCount the words
  10. AdvancedCaesar cipher
  11. AdvancedWrite your own strlen and strcat
  12. AdvancedAnagram check
  13. AdvancedRun-length encoding

6. Functions

  1. BeginnerMaximum of three numbers
  2. BeginnerShow seconds as hours, minutes and seconds (void function)
  3. BeginnerLeap year function
  4. BeginnerConvert Celsius to Fahrenheit (double return value)
  5. IntermediateRead a number backwards (pass by value)
  6. IntermediateSum and maximum of an array
  7. IntermediateReverse an array
  8. IntermediatePerfect numbers (prototype declaration)
  9. IntermediateReturn a grade from a score (char return value)
  10. AdvancedWas the maximum updated? (static variable)
  11. AdvancedBank account deposits and withdrawals (global variable)
  12. AdvancedDay of the year (combining functions)
  13. AdvancedSort an array in ascending order

7. Recursion

  1. BeginnerSum from 1 to N (recursive)
  2. BeginnerPower (recursive)
  3. BeginnerCount the digits (recursive)
  4. BeginnerFibonacci numbers
  5. IntermediatePrint a string in reverse
  6. IntermediatePrint in binary
  7. IntermediateMaximum of an array (recursive)
  8. IntermediatePalindrome check (recursive)
  9. AdvancedTower of Hanoi
  10. AdvancedBinary search (recursive version)
  11. AdvancedNumber of combinations nCr
  12. AdvancedList all permutations

8. Pointers

  1. BeginnerSwap two values
  2. BeginnerReturn the quotient and remainder at once
  3. BeginnerSum of an array using a pointer
  4. BeginnerCount the length of a string
  5. IntermediateReturn the maximum and minimum
  6. IntermediateReverse an array
  7. IntermediateConvert lowercase to uppercase
  8. IntermediateSearch for a value and return a pointer
  9. IntermediateSort three values in ascending order
  10. AdvancedDynamic array with malloc
  11. AdvancedA new string joining two strings
  12. AdvancedSort names with pointers to pointers

9. Structures

  1. BeginnerA point structure
  2. BeginnerData for one student
  3. BeginnerConvert a time to seconds
  4. IntermediateGrade table with an array of structures
  5. IntermediateUpdate an account through a pointer
  6. IntermediateReturn the midpoint of two points
  7. IntermediateGrades in three subjects (array inside a structure)
  8. IntermediateIs a point inside a rectangle? (nested structures)
  9. AdvancedSort a grade table by score
  10. AdvancedAdding and reducing fractions
  11. AdvancedInventory management

10. Review & Final Exam Prep

  1. BeginnerAssign a class
  2. BeginnerEven/odd, quotient and remainder
  3. BeginnerPrint weights in aligned columns
  4. BeginnerEvaluate a formula with three variables
  5. BeginnerA function that prints a smiley
  6. BeginnerArea of a rectangle (prototype)
  7. BeginnerFunction-like macros and parentheses
  8. BeginnerAn int function and a double function
  9. IntermediateDraw a frame with diagonals
  10. IntermediateDraw a grid (global variables and functions)
  11. IntermediateA function that draws a bar chart
  12. IntermediateA menu-driven calculator (global variables)
  13. IntermediateReturn the sum and average through pointers
  14. IntermediateDistance between two points (struct and function)
  15. IntermediateCapitalize the first letter of each word
  16. AdvancedDecide the result of tic-tac-toe
  17. AdvancedDifference from the average (malloc)
  18. AdvancedWrite scores to a file and read them back
  19. AdvancedSort in ascending or descending order
  20. AdvancedA Reverse Polish Notation calculator
  21. AdvancedSearch a member list (struct, strings, functions)
  22. BeginnerVowel or consonant (fill in the blanks)
  23. IntermediateA four-operation calculator (fill in the blanks)
  24. IntermediateCompare string lengths (fill in the blanks)
  25. AdvancedCount dice (fill in the blanks)
  26. AdvancedPseudo-random numbers by the linear congruential method (fill in the blanks)
  27. IntermediateCopy an array in reverse (fill in the blanks)
  28. IntermediateMatrix multiplication (fill in the blanks)
  29. IntermediateDouble an array through a pointer (fill in the blanks)
  30. AdvancedInsert at the head of a linked list (fill in the blanks)
Share this article
Share on X (Twitter) Share on Facebook Share on LinkedIn Share on Reddit