Writing Simple C Programs: A Cool Starter Pack

 


So you’ve met variables, constants, and data types. You can already print cool stuff with printf and grab user input with scanf. But here’s the question every beginner programmer asks:


👉 “What can I actually build with this knowledge?” 

The answer is: a lot more than you think

Not every program has to be packed with loops, conditions, and complex logic. In fact, the best way to build confidence is by solving real-life problems using straightforward formulas. Think of these programs as your warm-up exercises before you hit the advanced coding gym. Let’s dive into a few examples where we’ll follow a consistent approach: 

Problem Statement → Understanding the Problem → Code → Code Walkthrough

Problem 1: Calculating Simple Interest 

📝 Problem Statement 

Write a C program to calculate the simple interest given principal amount, rate of interest, and time. 


Write a C program to calculate the simple interest given principal amount, rate of interest, and time. Formula reminder: 

SI = \frac{P \times R \times T}{100}

Where:

  • P = Principal (money borrowed or invested) 
  • R = Rate of interest (per year) 
  • T = Time (in years)
🔍 Understanding the Problem 
If you lend ₹5000 at 10% interest for 2 years:
SI = \frac{5000 \times 10 \times 2}{100} = 1000 
So, the program should: 
  • Take P, R, T as input.
  • Apply the formula. 
  • Print the result. 
💻 Code
int main() {
float P, R, T, SI;
printf("Enter Principal: ");
scanf("%f", &P);
printf("Enter Rate of Interest: ");
scanf("%f", &R);
printf("Enter Time (in years): ");
scanf("%f", &T);
SI = (P * R * T) / 100;
printf("Simple Interest = %.2f\n", SI);
return 0;
}

🧩 Code Walkthrough 
  • Variables P, R, T, SI store user input and the result.
  • Formula (P * R * T) / 100 is applied directly. 
  • printf outputs the answer with two decimal precision.

Problem 2: Temperature Conversion (Celsius to Fahrenheit) 

Convert temperature from Celsius to Fahrenheit.
Formula: 
F = (C \times \frac{9}{5}) + 32 

🔍 Understanding the Problem 
If it’s 30°C in Kolkata: 
F = (30 \times 9/5) + 32 = 86 

💻 Code
int main() {
float C, F;
printf("Enter temperature in Celsius: ");
scanf("%f", &C);
F = (C * 9/5) + 32;
printf("Temperature in Fahrenheit = %.2f\n", F);
return 0;
}

🧩 Code Walkthrough 
  • Input Celsius (C). 
  • Apply the formula to get Fahrenheit (F). 
  • Print the result. Done. 
📝 Problem Statement 
Find the area of a circle given its radius.
 Formula: 
Area = \pi \times r^2 
Take π = 3.1416. 

🔍 Understanding the Problem 
If radius r = 7:
Area = 3.1416 \times 7 \times 7 = 153.94

💻 Code 
#include <stdio.h>
#define PI 3.1416
int main() {
float r, area;
printf("Enter radius of circle: ");
scanf("%f", &r);
area = PI * r * r;
printf("Area of Circle = %.2f\n", area);
return 0;
}

🧩 Code Walkthrough
  • #define PI 3.1416 defines a constant at the top. 
  • Formula area = PI * r * r; is applied directly. 
  • Output formatted with two decimal places.

🎯 Practice Problems [Set 1] for You 

Now that you’ve seen some worked-out examples, try solving these yourself. (Hint: follow the same Problem → Code → Walkthrough approach!) 

1. Perimeter of a Rectangle 
Formula: 
Perimeter = 2 \times (length + width)

2. Convert Kilometers to Miles 
Formula:
miles = km \times 0.621371

3. BMI Calculator 
Formula: 
BMI = \frac{weight}{height^2}

4. Total and Average of Three Numbers 
Input three numbers, calculate their sum and average. 
5. Area of a Triangle (using base and height) 
Formula: 
Area = \frac{1}{2} \times base \times height 

The Solution of Practice Problems Set 1 would be published in time. So, don't wait, get it done

🌟 Wrap-Up 

See how fun this is? With just a handful of concepts — variables, constants, inputs, formulas, and outputs — you’ve already built programs that connect directly to real-world scenarios. 
No loops, no conditions, no stress. Just math meeting code.
👉 Master these, and you’ll be fully ready to step into loops, decisions (if-else), and more advanced projects in C. 
Remember: programming isn’t about memorizing syntax. It’s about learning how to make a machine solve your problems. Start small, stay curious, and keep coding! 

Previous Post Next Post