Wednesday, 2 September 2026

Basic C Programs with Output for Beginners

Introduction to C Programming: 7 Basic C Programs with Output for Beginners

C programming is one of the most popular and powerful programming languages for beginners. It was developed by Dennis Ritchie at Bell Laboratories. C is often called a foundation programming language because many modern programming languages such as C++, Java, and others have been influenced by C.

C programming is widely used in system programming, operating systems, embedded systems, application development, and software development. Learning basic C programs helps students understand important programming concepts such as variables, data types, input and output, operators, expressions, and conditional statements.

📑 C Programs Covered in This Tutorial

  1. Hello World Program in C
  2. Sum of Two Numbers in C
  3. Average of Three Numbers in C
  4. Arithmetic Operations on Two Numbers in C
  5. Simple Interest Program in C
  6. Temperature Conversion Program in C
  7. Maximum of Three Numbers Using Conditional Operator

1. Program to Display Hello Message in C

The following is a simple Hello World program in C. It uses the printf() function to display a message on the screen.

📌 C Program

#include <stdio.h>

int main()
{
    printf("Hello, Welcome to C Programming!");
    
    return 0;
}

💻 Output

Hello, Welcome to C Programming!

2. Program to Find Sum of Two Numbers in C

This C program takes two numbers as input from the user using the scanf() function and calculates their sum using the addition operator +.

📌 C Program

#include <stdio.h>

int main()
{
    int num1, num2, sum;

    printf("Enter first number: ");
    scanf("%d", &num1);

    printf("Enter second number: ");
    scanf("%d", &num2);

    sum = num1 + num2;

    printf("Sum = %d", sum);

    return 0;
}

💻 Sample Output

Enter first number: 10
Enter second number: 20
Sum = 30

3. Program to Find Average of Three Numbers in C

This program accepts three numbers from the user and calculates their average. The float data type is used to store decimal values.

📌 Formula

Average = (Number1 + Number2 + Number3) / 3

📌 C Program

#include <stdio.h>

int main()
{
    float num1, num2, num3, average;

    printf("Enter three numbers: ");
    scanf("%f %f %f", &num1, &num2, &num3);

    average = (num1 + num2 + num3) / 3;

    printf("Average = %.2f", average);

    return 0;
}

💻 Sample Output

Enter three numbers: 10 20 30
Average = 20.00

4. Program to Perform All Four Arithmetic Operations in C

This program performs the four basic arithmetic operations on two numbers: addition, subtraction, multiplication, and division.

📌 Arithmetic Operators Used in C

  • + for Addition
  • - for Subtraction
  • * for Multiplication
  • / for Division

📌 C Program

#include <stdio.h>

int main()
{
    float num1, num2;

    printf("Enter two numbers: ");
    scanf("%f %f", &num1, &num2);

    printf("\nAddition = %.2f", num1 + num2);
    printf("\nSubtraction = %.2f", num1 - num2);
    printf("\nMultiplication = %.2f", num1 * num2);

    if(num2 != 0)
        printf("\nDivision = %.2f", num1 / num2);
    else
        printf("\nDivision is not possible because divisor is zero.");

    return 0;
}

💻 Sample Output

Enter two numbers: 20 5

Addition = 25.00
Subtraction = 15.00
Multiplication = 100.00
Division = 4.00

5. Program to Find Simple Interest in C

This C program calculates simple interest by taking the principal amount, rate of interest, and time from the user.

📌 Simple Interest Formula

Simple Interest = (Principal × Rate × Time) / 100

📌 C Program

#include <stdio.h>

int main()
{
    float principal, rate, time, simpleInterest;

    printf("Enter Principal Amount: ");
    scanf("%f", &principal);

    printf("Enter Rate of Interest: ");
    scanf("%f", &rate);

    printf("Enter Time in Years: ");
    scanf("%f", &time);

    simpleInterest = (principal * rate * time) / 100;

    printf("Simple Interest = %.2f", simpleInterest);

    return 0;
}

💻 Sample Output

Enter Principal Amount: 10000
Enter Rate of Interest: 5
Enter Time in Years: 2

Simple Interest = 1000.00

6. Program for Temperature Conversion in C

This program converts temperature from Celsius to Fahrenheit.

📌 Temperature Conversion Formula

Fahrenheit = (Celsius × 9 / 5) + 32

📌 C Program

#include <stdio.h>

int main()
{
    float celsius, fahrenheit;

    printf("Enter temperature in Celsius: ");
    scanf("%f", &celsius);

    fahrenheit = (celsius * 9 / 5) + 32;

    printf("Temperature in Fahrenheit = %.2f", fahrenheit);

    return 0;
}

💻 Sample Output

Enter temperature in Celsius: 25

Temperature in Fahrenheit = 77.00

7. Program to Find Maximum of Three Numbers Using Conditional Operator in C

This program finds the largest number among three numbers using the conditional operator. The conditional operator ? : is also known as the ternary operator in C programming.

📌 Syntax of Conditional Operator

condition ? expression1 : expression2;

📌 C Program

#include <stdio.h>

int main()
{
    int a, b, c, max;

    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

    max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);

    printf("Maximum number = %d", max);

    return 0;
}

💻 Sample Output

Enter three numbers: 10 25 18

Maximum number = 25

📚 Summary of Basic C Programs

These basic C programs are useful for beginners who are learning C programming and preparing for programming practicals, assignments, viva questions, and coding practice.

Program No. C Program Name
1 Hello World Program in C
2 Sum of Two Numbers in C
3 Average of Three Numbers in C
4 Four Arithmetic Operations in C
5 Simple Interest Program in C
6 Temperature Conversion Program in C
7 Maximum of Three Numbers Using Conditional Operator in C

Program to Calculate the Area of a Circle

Aim

To write a C program to calculate the area of a circle.

Formula

Area of Circle = Ï€ × r × r

Where r is the radius of the circle and π = 3.14159.

C Program

#include <stdio.h>

int main()
{
    float radius, area;

    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);

    area = 3.14159 * radius * radius;

    printf("Area of the circle = %.2f", area);

    return 0;
}

Sample Output

Enter the radius of the circle: 5
Area of the circle = 78.54

Online Area of Circle Calculator

Enter the radius below to calculate the area of the circle:




Example

If the radius of the circle is 5 units:

Area = Ï€ × r × r
= 3.14159 × 5 × 5
= 78.54 square units

🎯 Practice is the Key to Learning C Programming!

These basic C programs help beginners understand important concepts such as input and output, variables, arithmetic operators, conditional operators, and mathematical calculations in C programming. Try changing the input values and experiment with these programs to improve your programming skills.

No comments:

Post a Comment

Basic C Programs with Output for Beginners

Introduction to C Programming: 7 Basic C Programs with Output for Beginners C programming is one of the most popular and powe...