Basic C Programming QA || C Program

 

30 Basic C Programming Exercises for Beginners with Solutions

Master the fundamentals of C programming with these 30 beginner-friendly exercises. These challenges are designed to strengthen your understanding of C concepts, such as variables, data types, control flow, and functions. Build a solid foundation for more advanced programming challenges!

Learning Objectives:

By completing these exercises, you will:

  • Understand basic C syntax and structure.
  • Learn how to use variables and data types effectively.
  • Develop logical thinking with control flow statements.
  • Gain hands-on experience with simple functions.

Instructions:

  1. Attempt each exercise before checking the hint or solution.
  2. Focus on understanding the logic behind the solutions.
  3. Use these exercises to reinforce learning and identify areas that need improvement.

Exercises

1. Calculate the area of a circle

Input:

radius = 5

Expected Output:

Area = 78.54

#include <stdio.h>

int main() {
  float radius = 5; // Example input
  float area;

  // Logic to calculate area
  return 0;
}

2. Calculate the perimeter of a rectangle

Input:

length = 10, width = 5

Expected Output:

Perimeter = 30

#include <stdio.h>

int main() {
  int length = 10, width = 5;
  int perimeter;

  // Logic to calculate perimeter
  return 0;
}

3. Calculate the average of three numbers

Input:

num1 = 7, num2 = 13, num3 = 19

Expected Output:

Average = 13.0

#include <stdio.h>

int main() {
  int num1 = 7, num2 = 13, num3 = 19;
  float average;

  // Logic to calculate average
  return 0;
}

4. Check if a number is even or odd

Input:

number = 42

Expected Output:

Even

#include <stdio.h>

int main() {
  int number = 42;

  // Logic to check even or odd
  return 0;
}

5. Find the larger of two numbers

Input:

num1 = 5, num2 = 10

Expected Output:

Larger number = 10

#include <stdio.h>

int main() {
  int num1 = 5, num2 = 10;
  int larger;

  // Logic to find the larger number
  return 0;
}

6. Find the factorial of a number

Input:

number = 5

Expected Output:

Factorial = 120

#include <stdio.h>

int main() {
  int number = 5;
  int factorial = 1;

  // Logic to calculate factorial
  return 0;
}

7. Reverse a three-digit number

Input:

number = 123

Expected Output:

Reversed = 321

#include <stdio.h>

int main() {
  int number = 123;
  int reversed = 0;

  // Logic to reverse the number
  return 0;
}

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

Input:

number = 345

Expected Output:

Sum = 12

#include <stdio.h>

int main() {
  int number = 345;
  int sum = 0;

  // Logic to find the sum of digits
  return 0;
}

9. Convert Celsius to Fahrenheit

Input:

celsius = 25

Expected Output:

Fahrenheit = 77.0

#include <stdio.h>

int main() {
  float celsius = 25;
  float fahrenheit;

  // Logic to convert Celsius to Fahrenheit
  return 0;
}

10. Find the smallest of three numbers

Input:

a = 5, b = 3, c = 9

Expected Output:

Smallest = 3

#include <stdio.h>

int main() {
  int a = 5, b = 3, c = 9;
  int smallest;

  // Logic to find smallest
  return 0;
}


Comments

Popular posts from this blog

Series Completion QA || Reasoning