Exercices On C Programming Language
Exercices On C Programming Language
Exercises on C Programming
1. Basics of C Programming
2. Control Structures
Write a program that checks whether a number entered by the user is positive,
negative, or zero using if-else statements.
Use a switch statement to create a simple calculator that performs addition,
subtraction, multiplication, or division based on user input.
Write a program to print the multiplication table of a number entered by the user using
a for loop.
3. Functions
Define a function to find the maximum of two numbers. Use this function in main()
with user-input values.
Write a program that computes the factorial of a number using recursion.
Write a program with a user-defined function that calculates the sum of all elements in
an array.
4. Arrays
Write a program to read 10 integers from the user, store them in an array, and print the
sum and average of the numbers.
Create a program that sorts an array of integers in ascending order using the Bubble
Sort algorithm.
Develop a program that finds the smallest and largest elements in an array.
5. Pointers
Create a program that demonstrates the use of pointers by printing the address and
value of a variable.
Write a program to swap two numbers using pointers.
Implement a program that dynamically allocates memory for an array using malloc()
and then frees the memory.
6. Strings
Write a program to count the number of vowels, consonants, digits, and whitespace
characters in a string.
Create a function to reverse a string without using predefined string functions.
Write a program to check if a string is a palindrome (reads the same forward and
backward).
7. File Handling
Write a program to write a series of numbers into a file and then read them back to
display on the console.
Develop a program to count the number of words in a text file.
Write a program to copy the content of one file to another.
8. Advanced Topics
Use structures to define a Student record with fields like name, roll number, and
marks. Write a program to create and display details of 5 students.
Create a program that uses a structure and a union, highlighting their differences in
memory allocation.
Write a program to demonstrate the use of command-line arguments by calculating the
sum of integers passed as arguments.
Additional Challenges
Implement a program that calculates the Fibonacci sequence both iteratively and
recursively, and compare their execution times.
Write a program that uses pointers and functions to transpose a 2D matrix.
Create a program that simulates a simple banking system using functions and
structures.