C program to add subtract divide multiply two numbers

Write a C program to input two numbers and perform addition, subtraction, multiplication, division and modulus operations of two numbers. C program to perform all arithmetic operations of given two numbers.

 

Example: 
Input first number: 5 
Input second number: 5
Output: 
Sum = 10 
Difference = 0
Product = 25
Quotient = 1.000000
Modulus = 0

Required knowledge:

Fundamentals of C, Data types, Taking user input in C 

Program:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
 * C program to perform addition, subtraction, multiplication, division two numbers
 */
#include <stdio.h>
void main()
{
    int num1, num2;
    int sum, sub, mult, mod;
    float div;
    /*
     * Read two numbers from user
     */
    printf("Enter any two numbers : \n");
    scanf("%d%d", &num1, &num2);
    /*
     * Performs all arithmetic operations
     */
    sum = num1 + num2;
    sub = num1 - num2;
    mult = num1 * num2;
    div = (float)num1 / num2;
    mod = num1 % num2;
    /*
     * Prints the result of all arithmetic operations
     */
    printf("Sum = %d\n", sum);
    printf("Difference = %d\n", sub);
    printf("Product = %d\n", mult);
    printf("Quotient = %f\n", div);
    printf("Modulus = %d", mod);
}


Output
X
_
Enter any two numbers :
10
2
Sum = 12
Difference = 8
Product = 20
Quotient = 5.000000
Modulus = 0

Enjoy it....................

Comments

Popular posts from this blog

C program to calculate velocity

C program to find square root of a number

C program to find maximum between two numbers