C Exercises - Practice Questions With Solutions For C Programming
C Exercises - Practice Questions With Solutions For C Programming
So, Keep it Up! Solve topic-wise C exercise questions to strengthen your weak
topics.
C Programming Exercises
The following are the top 30 programming exercises with solutions to help
you practice online and improve your coding efficiency in the C language. You
can solve these questions online in GeeksforGeeks IDE.
In this problem, you have to write a simple program that prints "Hello World!"
on the console screen.
Open In App
For Example,
Q2: Write a Program to find the Sum of two numbers entered by the
user.
In this problem, you have to write a program that adds two numbers and
prints their sum on the console screen.
For Example,
Q3: Write a Program to find the size of int, float, double, and char.
In this problem, you have to write a program to print the size of the variable.
For Example,
In this problem, you have to write a program that swaps the values of two
variables that are entered by the user.
Open In App
Swap two numbers
For Example,
In this problem, you have to write a program that takes principal, time, and
rate as user input and calculates the compound interest.
For Example,
In this problem, you have to write a program to check whether the given
number is even or odd. Open In App
For Example,
Output: even
In this problem, you have to write a program to take three numbers from the
user as input and print the largest number among them.
For Example,
In this problem, you have to write a program to make a simple calculator that
accepts two operands and an operator to perform the calculation and prints
the result.
For Example,
Output: 15.0
In this problem, you have to write a program to calculate the factorial (product
of all the natural numbers less than or equal to the given number n) of a
number entered by the user.
Factorial
For Example,
In this problem, you have to write a program to convert the given binary
number entered by the user into an equivalent decimal number.
For Example,
Fibonacci Series
For Example,
Output: 0 1 1 2 3 5 8 13 21
In this problem, you have to write a program to calculate the sum of natural
numbers up to a given number n.
For Example,
Output: 55
For Example,
Reverse an array
For Example,
For Example,
In this problem, you have to write a program that takes a sorted array arr[] of
size N from the user and removes the duplicate elements from the array.
For Example,
In this problem, you have to write a program that takes an array arr[] of size N
and a target value to be searched by the user. Search the target value using
binary search if the target value is found print its index else print 'element is
not present in array'.
For Example,
Open In App
Click here to view the solution.
In this problem, you have to write a program that takes a pointer to the head
node of a linked list, you have to reverse the linked list and print the reversed
linked list.
For Example,
Input : 1->2->3->4->NULL
For Example,
In this problem, you have to write a program to find the transpose of a matrix
for a given matrix A with dimensions m x n and print the transposed matrix.
The transpose of a matrix is formed by interchanging its rows with columns.
For Example,
Input : matrix A:
{ {1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3},
Open In App
{4, 4, 4, 4} }
Output : Result matrix is :
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
In this problem, you have to write a program to read two strings str1 and str2
entered by the user and concatenate these two strings. Print the
concatenated string.
For Example,
Output: helloworld
In this problem, you have to write a program to read a string str entered by the
user and check whether the string is palindrome or not. If the str is
palindrome print 'str is a palindrome' else print 'str is not a palindrome'. A
string is said to be palindrome if the reverse of the string is the same as the
string.
For Example,
In this problem, you have to write a simple program to read a string str
entered by the user and print the first letter of each word in a string.
For Example,
Output: G f G
In this problem, you have to write a program to read a string str entered by the
user, and reverse that string means changing the order of characters in the
string so that the last character becomes the first character of the string
using recursion.
reverse a string
For Example,
Open In App
Q24: Write a program to Print Half half-pyramid pattern.
In this problem, you have to write a simple program to read the number of
rows (n) entered by the user and print the half-pyramid pattern of numbers.
Half pyramid pattern looks like a right-angle triangle of numbers having a
hypotenuse on the right side.
For Example,
Output:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
In this problem, you have to write a simple program to read the number of
rows (n) entered by the user and print Pascal’s triangle pattern. Pascal’s
Triangle is a pattern in which the first row has a single number 1 all rows
begin and end with the number 1. The numbers in between are obtained by
adding the two numbers directly above them in the previous row.
Pascal's Triangle
For Example,
Open In App
Input: Enter number of rows: 5
Output:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
In this problem, you have to write a program that takes an array arr[] of size N
from the user and sorts the array elements in ascending or descending order
using insertion sort.
For Example,
Output: 5 6 11 12 13
In this problem, you have to write a program that takes an array arr[] of size N
from the user and sorts the array elements in ascending order using quick
sort.
For Example,
Output: 4 11 12 13 15 16 17 18 19
Open In App
Q28: Write a program to sort an array of strings.
In this problem, you have to write a program that reads an array of strings in
which all characters are of the same case entered by the user and sort them
alphabetically.
For Example,
Input: arr[] =
Q29: Write a program to copy the contents of one file to another file.
In this problem, you have to write a program that takes user input to enter the
filenames for reading and writing. Read the contents of one file and copy the
content to another file. If the file specified for reading does not exist or
cannot be opened, display an error message "Cannot open file: file_name" and
terminate the program else print "Content copied to file_name"
For Example,
In this problem, you have to write a program that stores information about
students using structure. The program should create various structures, each
representing a student's record. Initialize the records with sample data having
data members' Names, Roll Numbers, Ages, and Total Marks. Print the
information for each student.
For Example,
Open In App
Output: Student Records:
Name = Student1
Roll Number = 1
Age = 12
Total Marks = 78.50
Name = Student2
Roll Number = 5
Age = 10
Total Marks = 56.84
Conclusion
We hope after completing these C exercises you have gained a better
understanding of C concepts. Learning C language is made easier with this
exercise sheet as it helps you practice all major C concepts. Solving these C
exercise questions will take you a step closer to becoming a C programmer.
Answer:
Q2. What are the best practices for beginners starting with C
programming exercises?
Answer:
Answer:
Similar Reads
12 min read
6 min read
Open In App
C/C++ Program for String Search
C/C++ Program for Naive Pattern SearchingC/C++ Program for KMP AlgorithmC/C++ Program for Rabin-
Karp AlgorithmC/C++ Program for A Naive Pattern Searching QuestionC/C++ Program for Finite…
1 min read
2 min read
4 min read
2 min read
1 min read
5 min read
9 min read
Registered Address:
K 061, Tower K, Gulshan Vivante
Apartment, Sector 137, Noida,
Gautam Buddh Nagar, Uttar Pradesh,
201305
Advertise with us
Open In App
Computer DevOps System Inteview School GeeksforGeeks
Science Git Design Preparation Subjects Videos
Operating Linux High Level Competitive Mathematics DSA
Systems AWS Design Programming Physics Python
Computer Docker Low Level Design Top DS or Algo Chemistry Java
Network Kubernetes UML Diagrams for CP Biology C++
Database Azure Interview Guide Company-Wise Social Science Web
Management GCP Design Patterns Recruitment English Grammar Development
System DevOps OOAD Process Commerce Data Science
Software Roadmap System Design Company-Wise World GK CS Subjects
Engineering Bootcamp Preparation
Digital Logic Interview Aptitude
Design Questions Preparation
Engineering Puzzles
Maths
Software
Development
Software Testing
Open In App