C program to perform arithmetic operations

Topics

We are going to write a C program to enter two numbers and performs all the athematic operations such as ( Addition , subtraction, multiplication, division How to perform all arithmetic operation between two numbers in C programming. C program to find sum, difference, product, quotient and modulus of two given numbers.

#include <stdio.h>
int main()
{
    int num1, num2;
    int sum, sub, mult, mod;
    float div;

   /*
  Input of two numbers 
     */

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

     /*
  All the Arthematic operations  
     */
    sum = num1 + num2;
    sub = num1 - num2;
    mult = num1 * num2;
    div = (float)num1 / num2;
    mod = num1 % num2;

    /*
  Output 
     */
    printf("SUM = %d\n", sum);
    printf("DIFFERENCE = %d\n", sub);
    printf("PRODUCT = %d\n", mult);
    printf("QUOTIENT = %f\n", div);
    printf("MODULUS = %d", mod);

    return 0; 
}

Output

Enter any two numbers: 

4
5
SUM = 9
DIFFERENCE = -1
PRODUCT = 20
QUOTIENT = 0.800000
MODULUS = 4

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *