Addition, Subtraction, Multiplication and Division with Function



#include<stdio.h>

#include<conio.h>

// functions declaration

int add(int n1, int n2);

int subtract(int n1, int n2);

int multiply(int n1, int n2);

int divide(int n1, int n2);


// main function

int main()

{

  int num1, num2;


  printf("Enter two numbers: ");

  scanf("%d %d", &num1, &num2);


  printf("%d + %d = %d\n", num1, num2, add(num1, num2));

  printf("%d - %d = %d\n", num1, num2, subtract(num1, num2));

  printf("%d * %d = %d\n", num1, num2, multiply(num1, num2));

  printf("%d / %d = %d\n", num1, num2, divide(num1, num2));


  return 0;

}


// function to add two integer numbers

int add(int n1, int n2)

{

  int result;

  result = n1 + n2;

  return result;

}


// function to subtract two integer numbers

int subtract(int n1, int n2)

{

  int result;

  result = n1 - n2;

  return result;

}


// function to multiply two integer numbers

int multiply(int n1, int n2)

{

  int result;

  result = n1 * n2;

  return result;

}


// function to divide two integer numbers

int divide(int n1, int n2)

{

  int result;

  result = n1 / n2;

  return result;

}


Output:-

Enter two numbers: 20 5

20 + 5 = 25

20 – 5 = 15

20 * 5 = 100

20 / 5 = 4

Comments

Popular posts from this blog

Check whether the no entered is Palindrome or not

Calculate Factorial of a given no with help of Recursion

Find max. and min. element in the integer array