C program to perform the arithmetic operations by accepting the inputs
Algorithm
Step 1: Start
Step 2: Declare a, b and c
Step 3: Read the values of two numbers, and store in variable a and b
Step 4: Perform the arithmetic operations 
        c = a + b (Addition)
        c = a - b (Subtraction)
        c = a * b (Multiplication)
        c = a / b (Division)
        c = (a + b) / 2 (Average)
Step 5: Print the results
Step 6: End
kw.c
#include <stdio.h>
int main()
{
    float a, b, c;
    printf("———————————————————————————————————————————");
    printf("\nProgram to perform arithmetic operations");
    printf("\n———————————————————————————————————————————");
    printf("\nEnter the 1st number ");
    scanf("%f", &a);
    printf("\nEnter the 2nd number ");
    scanf("%f", &b);
    printf("———————————————————————————");
    c = a + b;
    printf("\n      Addition | %f", c);
    c = a - b;
    printf("\n   Subtraction | %f", c);
    c = a * b;
    printf("\nMultiplication | %f", c);
    c = a / b;
    printf("\n      Division | %f", c);
    printf("\n———————————————————————————\n");
    c = (a + b) / 2;
    printf("\nAverage of two numbers is %f", c);
    printf("\n———————————————————————————————————————————\n");
    return 0;
}
Output
kodingwindow@kw:~$ gcc kw.c
kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program to perform arithmetic operations ——————————————————————————————————————————— Enter the 1st number 25 Enter the 2nd number -5 ——————————————————————————— Addition | 20.000000 Subtraction | 30.000000 Multiplication | -125.000000 Division | -5.000000 ——————————————————————————— Average of two numbers is 10.000000 ——————————————————————————————————————————— kodingwindow@kw:~$
Advertisement