30 C Programming Basic Exercises for Beginners with Solutions

Master beginner C Programming skills with our comprehensive list of top 30 exercises. Dive into coding challenges that improve your understanding and proficiency in C Programming, setting a solid foundation for intermediate challenges. Start your journey to C Programming mastery today!

Learning Objectives:

By the end of these exercises, you will have a foundational understanding of C language basics, including variables, data types, control flow, and simple functions.

Exercise Instructions:

  • Start with the first exercise and attempt to solve it before checking the hint or solution.
  • Ensure you understand the logic behind each solution, as this will help you in more complex problems.
  • Use these exercises to reinforce your learning and identify areas that may require further study.

1. Calculate the area of a circle.

Required Input:

radius = 5

Expected Output:

Area = 78.54

Code In C

#include int main() { float radius = 5; // Example input float area; // Logic to calculate area return 0; }

Output

Click Run Button to view compiled output

2. Calculate the perimeter of a rectangle.

Required Input:

length = 10, width = 5

Expected Output:

Perimeter = 30

Code In C

#include int main() { int length = 10, width = 5; int perimeter; // Logic to calculate perimeter return 0; }

Output

Click Run Button to view compiled output

3. Calculate the average of three numbers.

Required Input:

num1 = 7, num2 = 13, num3 = 19

Expected Output:

Average = 13.0

Code In C

#include int main() { int num1 = 7, num2 = 13, num3 = 19; float average; // Logic to calculate average return 0; }

Output

Click Run Button to view compiled output

4. Check if a number is even or odd.

Required Input:

number = 42

Expected Output:

Even

Code In C

#include int main() { int number = 42; // Logic to check even or odd return 0; }

Output

Click Run Button to view compiled output

5. Find the larger of two numbers.

Required Input:

num1 = 5, num2 = 10

Expected Output:

Larger number = 10

Code In C

#include int main() { int num1 = 5, num2 = 10; int larger; // Logic to find the larger number return 0; }

Output

Click Run Button to view compiled output

6. Find the factorial of a number.

Required Input:

number = 5

Expected Output:

Factorial = 120

Code In C

#include int main() { int number = 5; int factorial = 1; // Logic to calculate factorial return 0; }

Output

Click Run Button to view compiled output

7. Reverse a three-digit number.

Required Input:

number = 123

Expected Output:

Reversed = 321

Code In C

#include int main() { int number = 123; int reversed = 0; // Logic to reverse the number return 0; }

Output

Click Run Button to view compiled output

8. Find the sum of digits of a three-digit number.

Required Input:

number = 345

Expected Output:

Sum = 12

Code In C

#include int main() { int number = 345; int sum = 0; // Logic to find the sum of digits return 0; }

Output

Click Run Button to view compiled output

9. Convert Celsius to Fahrenheit.

Required Input:

celsius = 25

Expected Output:

Fahrenheit = 77.0

Code In C

#include int main() { float celsius = 25; float fahrenheit; // Logic to convert Celsius to Fahrenheit return 0; }

Output

Click Run Button to view compiled output

10. Find the smallest of three numbers.

Required Input:

a = 5, b = 3, c = 9

Expected Output:

Smallest = 3

Code In C

#include int main() { int a = 5, b = 3, c = 9; int smallest; // Logic to find smallest return 0; }

Output

Click Run Button to view compiled output

ad vertical

1 of 3