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)
- Take P, R, T as input.
- Apply the formula.
- Print the result.
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;}
- 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)
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;}
- Input Celsius (C).
- Apply the formula to get Fahrenheit (F).
- Print the result. Done.
#include <stdio.h>#define PI 3.1416int 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;}
- #define PI 3.1416 defines a constant at the top.
- Formula area = PI * r * r; is applied directly.
- Output formatted with two decimal places.