LearnFrenzy
Sign in Take a free test

C Programming · Practice by type

C Programming Programs for Practice with Output

Practice programs for every C Programming topic, each with a full solution, its real output and an explanation. Try writing each one yourself first.

  • 184 questions
  • 23 topics
  • Answers checked on a real compiler

Declarations and Initializations 8 questions

  1. Student record with designated initializers in C Easy
  2. Days in each quarter from an initialised array in C Easy
  3. Remainder and rounding of real numbers in C Easy
  4. Default settings and an update with a compound literal in C Medium
  5. HTTP status codes as an enum with explicit values in C Medium
  6. String array vs string literal: modify a copy safely in C Medium
  7. Fill a zero-initialised 2D array with a times table in C Easy
  8. Slot bookings with C23 constexpr and nullptr Hard

Control Instructions 8 questions

  1. Largest of three numbers in C (nested if and ternary) Easy
  2. Roots of a quadratic equation in C Medium
  3. Electricity bill calculation with slabs in C Medium
  4. Day of the week from a number using switch in C Easy
  5. Check vowel, consonant, digit or special character in C Easy
  6. Rock, paper, scissors winner logic in C Medium
  7. Validate a date (day, month, year) in C Medium
  8. Menu-driven ATM program in C (do-while + switch) Medium

Floating Point Issues 8 questions

  1. Compare two doubles with a relative tolerance in C Medium
  2. Kahan summation vs naive summation in C Hard
  3. Store and print money in paise (integer) in C Medium
  4. Area and circumference of a circle with a portable π in C Easy
  5. Show why 0.1 is inexact: decimal fraction to binary in C Medium
  6. Mean and standard deviation of an array in C Medium
  7. Percentage of marks without integer-division bugs in C Easy
  8. Classify floating-point values with fpclassify() in C Hard

Functions 8 questions

  1. GCD and LCM using functions in C Easy
  2. Prime number function in C (check up to √n) Easy
  3. Find the maximum of an array using recursion in C Medium
  4. Fibonacci series using a function in C (iterative) Easy
  5. Decimal to binary using recursion in C Medium
  6. Check a palindrome number using a function in C Easy
  7. Armstrong numbers between 1 and 1000 using functions in C Medium
  8. Count elements with a callback (function pointer) in C Hard

Pointers 8 questions

  1. C program to swap two numbers using pointers Easy
  2. Sum and average of an array using a pointer in C Easy
  3. C program to reverse an array using pointers Medium
  4. String length using a pointer in C (without strlen) Easy
  5. C program to sort an array using pointers (bubble sort) Medium
  6. C program to count vowels and consonants using a pointer Easy
  7. C program to read n numbers into a malloc array Medium
  8. C program to copy a string using pointers (without strcpy) Medium

Strings 8 questions

  1. Reverse a string in place in C Easy
  2. Palindrome check ignoring case and punctuation in C Medium
  3. Check whether two strings are anagrams in C Medium
  4. Count words in a string in C (multiple spaces and tabs) Easy
  5. Reverse the words of a sentence in place in C Hard
  6. First non-repeating character in a string in C Medium
  7. Convert a string to an int safely with strtol() in C Hard
  8. Run-length encoding of a string in C Medium

C Input / Output 8 questions

  1. Print an aligned shopping bill with printf in C Easy
  2. Keep asking until a valid integer is entered in C Medium
  3. Parse comma-separated records with fgets and sscanf in C Medium
  4. Count letter frequency from input with getchar in C Medium
  5. Write marks to a file and compute totals with fscanf in C Medium
  6. Update one record in a binary file in place in C Hard
  7. Print a file backwards using fseek and ftell in C Hard
  8. Append log lines and show line numbers in C Medium

Arrays 8 questions

  1. Second largest element in an array in C Medium
  2. Rotate an array by k positions in C (reversal method) Medium
  3. Remove duplicates from a sorted array in place in C Medium
  4. Maximum subarray sum in C (Kadane's algorithm) Hard
  5. Binary search in C with the insert position (lower bound) Medium
  6. Merge two sorted arrays in C Easy
  7. Matrix multiplication program in C Medium
  8. Find the missing number in an array using XOR in C Medium

Data Types 8 questions

  1. Overflow-safe integer addition in C Medium
  2. Celsius to Fahrenheit in C without integer division Easy
  3. Digit sum of a very large number (long long) in C Easy
  4. Convert seconds into days, hours, minutes and seconds in C Easy
  5. Average of integers with correct rounding in C Medium
  6. ASCII values of characters and case conversion in C Easy
  7. Powers of two up to the 64-bit limit in C Medium
  8. Checked multiplication with C23 ckd_mul() Hard

C Variables 8 questions

  1. Count how many times a function is called in C Easy
  2. Fibonacci generator that remembers its state in C Medium
  3. Pseudo-random number generator with a static seed in C Hard
  4. Swap two variables in three ways in C Easy
  5. Track min and max readings with static variables in C Medium
  6. Factorial with a static cache array in C Medium
  7. A counter module with private state and a reset in C Easy
  8. Shopping cart total with file-scope variables in C Medium

C Const 8 questions

  1. Convert a number to Roman numerals with a const table in C Medium
  2. Month name from a number with a const pointer array in C Easy
  3. Const-correct letter, digit and space counter in C Easy
  4. GST calculation with a const table of rates in C Medium
  5. Default settings in a const struct, overridden in a copy Medium
  6. Unit conversion using a const table of factors in C Easy
  7. Largest element of a read-only array in C Easy
  8. Identity matrix with C23 constexpr sizes Hard

Structures, Unions, Enums 8 questions

  1. Student records: find the topper using structures in C Easy
  2. Distance between two points using a structure in C Easy
  3. Add two times (hh:mm:ss) using structures in C Medium
  4. Linked list in C: insert at end, delete a value, print Hard
  5. Sort structures by marks, then by name, in C Medium
  6. See the IEEE 754 bits of a float with a union in C Hard
  7. Traffic light state machine using an enum in C Medium
  8. Bank account with structures and functions in C Medium

Typedef 8 questions

  1. Fraction type with typedef struct and gcd reduction in C Medium
  2. Circular queue (ring buffer) with typedef struct in C Hard
  3. Apply a typedef'd callback to every array element in C Medium
  4. Date type: day of the year and days between dates in C Medium
  5. 2×2 matrix type: multiplication and determinant in C Medium
  6. Event dispatcher with a table of typedef'd handlers in C Medium
  7. XOR and sum checksums with a Byte typedef in C Medium
  8. Linked list with a Node typedef: append, length and free Medium

Bitwise Operators 8 questions

  1. Set, clear, toggle and test a bit with functions in C Easy
  2. Swap the two nibbles of a byte in C Easy
  3. Find the element that appears once (XOR) in C Medium
  4. Number of bits to flip to convert A into B in C Medium
  5. Rotate a 32-bit number left in C Hard
  6. Next power of two using bit tricks in C Hard
  7. Generate all subsets of a set using bitmasks in C Medium
  8. Check whether two integers have opposite signs in C Easy

Command Line Arguments 8 questions

  1. Sum and average of numbers given as command-line arguments Easy
  2. Reverse each command-line argument in C Easy
  3. Count vowels in all command-line arguments in C Easy
  4. Temperature converter taking value/unit pairs as arguments Medium
  5. An --upper option that changes how words are printed Medium
  6. Find where a word appears among the arguments in C Easy
  7. Convert decimal, hex and octal arguments with strtol(…, 0) Medium
  8. Repeat a word N times, with N from the command line Easy

C Loops 8 questions

  1. Reverse a number and find its digit sum in C Easy
  2. Perfect numbers up to 10000 in C Medium
  3. Fibonacci numbers below 100 with a while loop in C Easy
  4. Diamond star pattern in C Medium
  5. Frequency of each digit in a number in C Medium
  6. Collatz sequence: steps to reach 1 in C Medium
  7. Strong numbers (sum of digit factorials) in C Medium
  8. Largest of any number of inputs (until end of input) in C Easy

Memory Allocation 8 questions

  1. Concatenate two strings into new memory with malloc() in C Easy
  2. Read a line of any length with realloc() in C Hard
  3. Split a sentence into a heap array of words in C Hard
  4. A stack that grows with realloc() in C Medium
  5. Reverse a linked list in place in C Medium
  6. Write your own calloc() with an overflow check in C Hard
  7. Remove duplicates from an unsorted array with malloc in C Medium
  8. A simple arena (bump) allocator in C Hard

Variable Number of Arguments 8 questions

  1. Sum and average of any number of integers in C Easy
  2. Minimum and maximum of n doubles with va_arg in C Easy
  3. Join path parts until a NULL sentinel in C Medium
  4. A levelled logger built on vfprintf in C Medium
  5. Implement a mini printf with %d, %x, %s and %c in C Hard
  6. An asprintf-style function with vsnprintf and va_copy in C Hard
  7. Evaluate a polynomial with variadic coefficients in C Medium
  8. Print mixed values and a struct from a type string in C Hard

Complicated Declarations 8 questions

  1. Menu calculator with an array of function pointers in C Easy
  2. Generic map and filter with function-pointer parameters in C Medium
  3. Traffic-light state machine with function pointers in C Hard
  4. Transpose and print a matrix using pointers to arrays in C Medium
  5. Choose a qsort comparator at run time in C Hard
  6. Event handler registry with function pointers in C Medium
  7. Jagged array with an array of row pointers in C Medium
  8. Apply a function n times through a function pointer in C Easy

Operators and Expressions 8 questions

  1. Even or odd, positive or negative using operators in C Easy
  2. Simple interest and compound interest program in C Easy
  3. Convert days into years, weeks and days in C Easy
  4. Largest of three numbers using only the ternary operator Medium
  5. Area and perimeter of a rectangle and a circle in C Easy
  6. Clock time after adding minutes using % in C Medium
  7. BMI calculator with categories in C Easy
  8. Reverse a three-digit number without loops in C Easy

Decision Making 8 questions

  1. Largest of four numbers in C Easy
  2. Count vowels using logical OR conditions in C Easy
  3. Result with marks and attendance rules in C Medium
  4. Quadrant of a point (or which axis it lies on) in C Easy
  5. Check whether three sides form a right-angled triangle in C Medium
  6. Validate a time string HH:MM:SS in C Medium
  7. Discount calculation with a decision table in C Medium
  8. FizzBuzz without the % operator in C Hard

Error Handling 8 questions

  1. Safe division with error codes and messages in C Easy
  2. A robust integer parser using strtol and errno in C Medium
  3. Open several files and report each error with strerror in C Easy
  4. Release several resources with goto cleanup in C Medium
  5. Calculator that recovers from errors with setjmp in C Hard
  6. Detect factorial overflow with C23 ckd_mul Medium
  7. A bounded stack with overflow and underflow errors in C Easy
  8. Clean shutdown with atexit and exit in C Medium

C Library Functions 8 questions

  1. Roots of a quadratic equation using sqrt() in C Easy
  2. Mean, median and standard deviation with qsort and sqrt in C Medium
  3. Dictionary lookup of words with bsearch in C Hard
  4. Count words and find the longest with strtok in C Easy
  5. Days between two dates and the weekday with mktime in C Medium
  6. Caesar cipher using isalpha, isupper and islower in C Easy
  7. Sort names alphabetically ignoring case with qsort in C Medium
  8. Remove repeated characters from a string with memmove in C Hard

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links