C Program To Perform All Arithmetic Operations Using Functions

#include <stdio.h>
// @function to make Addition
int Addition(int p, int q) {
    return p + q;
}
// @function to make Subtraction
int Subtraction(int p, int q) {
    return p - q;
}
// @function to make Multiplication
int Multiplication(int p, int q) {
    return p * q;
}
// @function to make Division
float Division(int p, int q) {
    return (float)p / q;
}
// @function to make Modulus
int Modulus(int p, int q) {
    return p % q;
}
int main() {
    int p, q;
    // it will take two integer numbers
    printf("Enter any two positive integer numbers:\n");
    scanf("%d%d", &p, &q);
    // It will call the all user-defined function
    // Then, print the final output of the program
    printf("\n");
    printf("Addition of       %d + %d = %d\n", p, q, Addition(p, q));
    printf("Subtraction of    %d - %d = %d\n", p, q, Subtraction(p, q));
    printf("Multiplication of %d * %d = %d\n", p, q, Multiplication(p, q));
    printf("Division of       %d / %d = %f\n", p, q, Division(p, q));
    printf("Modulus of        %d %% %d = %d\n", p, q, Modulus(p, q));
    return 0;
}

Output:

Enter any two positive integer numbers:
5
7
Addition of       5 + 7 = 12
Subtraction of    5 - 7 = -2
Multiplication of 5 * 7 = 35
Division of       5 / 7 = 0.714286
Modulus of        5 % 7 = 5

Leave a Comment