C Program to Display Arithmetic Operations Using Function

In this program, we will perform arithmetic operations using function. A function is a block of statements that performs a specific task. Let's say you are writing a C program and you need to perform a same task in that program more than once. In such case you have two options: a) Use the same set of statements every time you want to perform the task. b) Create a function to perform that task, and just call it every time you need to perform that task.



Source Code
#include<stdio.h>
#include<conio.h>

void add(int p,int q);
void subtraction (int p,int q);
void multiplication(int p,int q);
void division(int p,int q);

void main()
{
    int a, b, sum, sub, mul, div;
    //clrscr();
    printf("Enter two numbers: ");
    scanf("%d %d",&a, &b);
    add(a, b);
    subtraction(a, b);
    multiplication(a, b);
    division(a, b);
    getch();
}
void add(int p, int q)
{
    int sum;
    sum = p + q;
    printf("Addition of a numbers is %d\n", sum);
}
void subtraction(int p, int q)
{
    int sub;
    sub = p - q;
    printf("subtraction of a number is %d\n", sub);
}
void multiplication(int p, int q)
{
    int mul;
    mul = p * q;
    printf("Multiplication of a number is %d\n", mul);
}
void division(int p, int q)
{
    float div;
    div = p / q;
    printf("Division of a number is %f", div);
}
Output
Enter two numbers: 8 3
Addition of a numbers is 11
subtraction of a number is 5
Multiplication of a number is 24
Division of a number is 2.000000





"Coding Hub - Learn to code" app now available on Google Play Store