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
- Student record with designated initializers in C Easy
- Days in each quarter from an initialised array in C Easy
- Remainder and rounding of real numbers in C Easy
- Default settings and an update with a compound literal in C Medium
- HTTP status codes as an enum with explicit values in C Medium
- String array vs string literal: modify a copy safely in C Medium
- Fill a zero-initialised 2D array with a times table in C Easy
- Slot bookings with C23 constexpr and nullptr Hard
Control Instructions 8 questions
- Largest of three numbers in C (nested if and ternary) Easy
- Roots of a quadratic equation in C Medium
- Electricity bill calculation with slabs in C Medium
- Day of the week from a number using switch in C Easy
- Check vowel, consonant, digit or special character in C Easy
- Rock, paper, scissors winner logic in C Medium
- Validate a date (day, month, year) in C Medium
- Menu-driven ATM program in C (do-while + switch) Medium
Floating Point Issues 8 questions
- Compare two doubles with a relative tolerance in C Medium
- Kahan summation vs naive summation in C Hard
- Store and print money in paise (integer) in C Medium
- Area and circumference of a circle with a portable π in C Easy
- Show why 0.1 is inexact: decimal fraction to binary in C Medium
- Mean and standard deviation of an array in C Medium
- Percentage of marks without integer-division bugs in C Easy
- Classify floating-point values with fpclassify() in C Hard
Functions 8 questions
- GCD and LCM using functions in C Easy
- Prime number function in C (check up to √n) Easy
- Find the maximum of an array using recursion in C Medium
- Fibonacci series using a function in C (iterative) Easy
- Decimal to binary using recursion in C Medium
- Check a palindrome number using a function in C Easy
- Armstrong numbers between 1 and 1000 using functions in C Medium
- Count elements with a callback (function pointer) in C Hard
Pointers 8 questions
- C program to swap two numbers using pointers Easy
- Sum and average of an array using a pointer in C Easy
- C program to reverse an array using pointers Medium
- String length using a pointer in C (without strlen) Easy
- C program to sort an array using pointers (bubble sort) Medium
- C program to count vowels and consonants using a pointer Easy
- C program to read n numbers into a malloc array Medium
- C program to copy a string using pointers (without strcpy) Medium
Strings 8 questions
- Reverse a string in place in C Easy
- Palindrome check ignoring case and punctuation in C Medium
- Check whether two strings are anagrams in C Medium
- Count words in a string in C (multiple spaces and tabs) Easy
- Reverse the words of a sentence in place in C Hard
- First non-repeating character in a string in C Medium
- Convert a string to an int safely with strtol() in C Hard
- Run-length encoding of a string in C Medium
C Input / Output 8 questions
- Print an aligned shopping bill with printf in C Easy
- Keep asking until a valid integer is entered in C Medium
- Parse comma-separated records with fgets and sscanf in C Medium
- Count letter frequency from input with getchar in C Medium
- Write marks to a file and compute totals with fscanf in C Medium
- Update one record in a binary file in place in C Hard
- Print a file backwards using fseek and ftell in C Hard
- Append log lines and show line numbers in C Medium
Arrays 8 questions
- Second largest element in an array in C Medium
- Rotate an array by k positions in C (reversal method) Medium
- Remove duplicates from a sorted array in place in C Medium
- Maximum subarray sum in C (Kadane's algorithm) Hard
- Binary search in C with the insert position (lower bound) Medium
- Merge two sorted arrays in C Easy
- Matrix multiplication program in C Medium
- Find the missing number in an array using XOR in C Medium
Data Types 8 questions
- Overflow-safe integer addition in C Medium
- Celsius to Fahrenheit in C without integer division Easy
- Digit sum of a very large number (long long) in C Easy
- Convert seconds into days, hours, minutes and seconds in C Easy
- Average of integers with correct rounding in C Medium
- ASCII values of characters and case conversion in C Easy
- Powers of two up to the 64-bit limit in C Medium
- Checked multiplication with C23 ckd_mul() Hard
C Variables 8 questions
- Count how many times a function is called in C Easy
- Fibonacci generator that remembers its state in C Medium
- Pseudo-random number generator with a static seed in C Hard
- Swap two variables in three ways in C Easy
- Track min and max readings with static variables in C Medium
- Factorial with a static cache array in C Medium
- A counter module with private state and a reset in C Easy
- Shopping cart total with file-scope variables in C Medium
C Const 8 questions
- Convert a number to Roman numerals with a const table in C Medium
- Month name from a number with a const pointer array in C Easy
- Const-correct letter, digit and space counter in C Easy
- GST calculation with a const table of rates in C Medium
- Default settings in a const struct, overridden in a copy Medium
- Unit conversion using a const table of factors in C Easy
- Largest element of a read-only array in C Easy
- Identity matrix with C23 constexpr sizes Hard
Structures, Unions, Enums 8 questions
- Student records: find the topper using structures in C Easy
- Distance between two points using a structure in C Easy
- Add two times (hh:mm:ss) using structures in C Medium
- Linked list in C: insert at end, delete a value, print Hard
- Sort structures by marks, then by name, in C Medium
- See the IEEE 754 bits of a float with a union in C Hard
- Traffic light state machine using an enum in C Medium
- Bank account with structures and functions in C Medium
Typedef 8 questions
- Fraction type with typedef struct and gcd reduction in C Medium
- Circular queue (ring buffer) with typedef struct in C Hard
- Apply a typedef'd callback to every array element in C Medium
- Date type: day of the year and days between dates in C Medium
- 2×2 matrix type: multiplication and determinant in C Medium
- Event dispatcher with a table of typedef'd handlers in C Medium
- XOR and sum checksums with a Byte typedef in C Medium
- Linked list with a Node typedef: append, length and free Medium
Bitwise Operators 8 questions
- Set, clear, toggle and test a bit with functions in C Easy
- Swap the two nibbles of a byte in C Easy
- Find the element that appears once (XOR) in C Medium
- Number of bits to flip to convert A into B in C Medium
- Rotate a 32-bit number left in C Hard
- Next power of two using bit tricks in C Hard
- Generate all subsets of a set using bitmasks in C Medium
- Check whether two integers have opposite signs in C Easy
Command Line Arguments 8 questions
- Sum and average of numbers given as command-line arguments Easy
- Reverse each command-line argument in C Easy
- Count vowels in all command-line arguments in C Easy
- Temperature converter taking value/unit pairs as arguments Medium
- An --upper option that changes how words are printed Medium
- Find where a word appears among the arguments in C Easy
- Convert decimal, hex and octal arguments with strtol(…, 0) Medium
- Repeat a word N times, with N from the command line Easy
C Loops 8 questions
- Reverse a number and find its digit sum in C Easy
- Perfect numbers up to 10000 in C Medium
- Fibonacci numbers below 100 with a while loop in C Easy
- Diamond star pattern in C Medium
- Frequency of each digit in a number in C Medium
- Collatz sequence: steps to reach 1 in C Medium
- Strong numbers (sum of digit factorials) in C Medium
- Largest of any number of inputs (until end of input) in C Easy
Memory Allocation 8 questions
- Concatenate two strings into new memory with malloc() in C Easy
- Read a line of any length with realloc() in C Hard
- Split a sentence into a heap array of words in C Hard
- A stack that grows with realloc() in C Medium
- Reverse a linked list in place in C Medium
- Write your own calloc() with an overflow check in C Hard
- Remove duplicates from an unsorted array with malloc in C Medium
- A simple arena (bump) allocator in C Hard
Variable Number of Arguments 8 questions
- Sum and average of any number of integers in C Easy
- Minimum and maximum of n doubles with va_arg in C Easy
- Join path parts until a NULL sentinel in C Medium
- A levelled logger built on vfprintf in C Medium
- Implement a mini printf with %d, %x, %s and %c in C Hard
- An asprintf-style function with vsnprintf and va_copy in C Hard
- Evaluate a polynomial with variadic coefficients in C Medium
- Print mixed values and a struct from a type string in C Hard
Complicated Declarations 8 questions
- Menu calculator with an array of function pointers in C Easy
- Generic map and filter with function-pointer parameters in C Medium
- Traffic-light state machine with function pointers in C Hard
- Transpose and print a matrix using pointers to arrays in C Medium
- Choose a qsort comparator at run time in C Hard
- Event handler registry with function pointers in C Medium
- Jagged array with an array of row pointers in C Medium
- Apply a function n times through a function pointer in C Easy
Operators and Expressions 8 questions
- Even or odd, positive or negative using operators in C Easy
- Simple interest and compound interest program in C Easy
- Convert days into years, weeks and days in C Easy
- Largest of three numbers using only the ternary operator Medium
- Area and perimeter of a rectangle and a circle in C Easy
- Clock time after adding minutes using % in C Medium
- BMI calculator with categories in C Easy
- Reverse a three-digit number without loops in C Easy
Decision Making 8 questions
- Largest of four numbers in C Easy
- Count vowels using logical OR conditions in C Easy
- Result with marks and attendance rules in C Medium
- Quadrant of a point (or which axis it lies on) in C Easy
- Check whether three sides form a right-angled triangle in C Medium
- Validate a time string HH:MM:SS in C Medium
- Discount calculation with a decision table in C Medium
- FizzBuzz without the % operator in C Hard
Error Handling 8 questions
- Safe division with error codes and messages in C Easy
- A robust integer parser using strtol and errno in C Medium
- Open several files and report each error with strerror in C Easy
- Release several resources with goto cleanup in C Medium
- Calculator that recovers from errors with setjmp in C Hard
- Detect factorial overflow with C23 ckd_mul Medium
- A bounded stack with overflow and underflow errors in C Easy
- Clean shutdown with atexit and exit in C Medium
C Library Functions 8 questions
- Roots of a quadratic equation using sqrt() in C Easy
- Mean, median and standard deviation with qsort and sqrt in C Medium
- Dictionary lookup of words with bsearch in C Hard
- Count words and find the longest with strtok in C Easy
- Days between two dates and the weekday with mktime in C Medium
- Caesar cipher using isalpha, isupper and islower in C Easy
- Sort names alphabetically ignoring case with qsort in C Medium
- Remove repeated characters from a string with memmove in C Hard
Ready to test your Programming?
Timed online tests with instant scores and explanations.