C Program to find Subtraction of two numbers

C Program to find Subtraction of two numbers

In this article, we will discuss the concept of the C program to find  Subtraction of two numbers

In this post, we are going to learn how to  write a program find the subtraction of two numbers in C programming language

Subtract two numbers

Code to find the subtraction of  two numbers 

Subtract two integer number

The program use to find subtraction of given two integer numbers

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num1=54,num2=67;
    //variable declaration and initialization
    int sub=num2-num1;
    //formula of subtraction

    printf("Difference of two numbers are: %d\n",sub);
    //display the result
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Difference of two numbers are: 13

 

Subtract two integer number using user input

This program allows the user to enter two numbers Then the program find the subtraction of the given two number

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num1,num2;
    //variable declaration

    printf("Enter the first number: ");
    scanf("%d",&num1);
    //read the first number

     printf("Enter the second number: ");
    scanf("%d",&num2);
    //read the second number

    int sub=num2-num1;
    //formula of subtraction

    printf("Differences of two numbers are: %d\n",sub);
    //display the result
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter the first number: 65
Enter the second number: 87
Differences of two numbers are:22


Case 2

Enter the first number: 90
Enter the second number:73
Differences of two numbers are:-23

 

 

Subtract two float numbers

The program use to find subtraction of given two floating point numbers

Program 3

#include <stdio.h>
#include <stdlib.h>

int main()
{
    float num1=54.53,num2=67.45;
    //variable declaration and initialization
    float sub=num2-num1;
    //formula of subtraction

    printf("Difference of two float numbers are: %.2f\n",sub);
    //display the result
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Difference of two float numbers are:12.92

 

Subtract two float number using user input

This program allows the user to enter two float numbers Then the program find the results of subtraction the given two number

Program 4

#include <stdio.h>
#include <stdlib.h>

int main()
{
    float num1,num2;
    //variable declaration

    printf("Enter the first number: ");
    scanf("%f",&num1);
    //read the first number

     printf("Enter the second number: ");
    scanf("%f",&num2);
    //read the second number

    float sub=num2-num1;
    //formula of subtraction

    printf("Differences of two numbers are: %.2f\n",sub);
    //display the result
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter the first number: 43.6
Enter the second number: 67.8
Differences of two numbers are:24.20

 

Case 2

Enter the first number: 65.4
Enter the second number:35.8
Differences of two numbers are:-29.60


Suggested for you

Operator in C language

Data type in C language

Variable in C language

input output function in C

 

 

Similar post

Find sum of two numbers in C

Find sum of two numbers in C using recursion

Find sum of two numbers in C using pointer

Find sum of two numbers in C without Arithmetic operator

Find sum of natural numbers in C language

Find sum of natural numbers in C language using recursion

 

Subtract two numbers in C++ programming
Subtract two numbers in Python programming
C examplesC language