So, we saw addition of two numbers in our previous blog .Now we will see about subtraction of two numbers.

Basic Data Type:- int, char, float, double

int Datatype:-Its an integer datatype .Its of 2 bytes .Its range is −32,768 to 32,767.

char Datatype:-Its an character datatype. Its of  1 byte. Its range is -128 to 127 .

float Datatype:-Its for floating point numbers. Its of  4 byte.

double Datatype :-Its for large floating point numbers .Its of 8 byte

1.    Subtraction of two numbers using the keyword int 

#include <stdio.h>

int main()

{

    int number1,number2,number3;

    printf("Enter number 1 and number 2 ");  

    scanf("%d %d",&number1,&number2);

    number3=number1-number2;

    printf("The subtraction of two numbers is %d",number3);

    return 0;

}

Algorithm:-

1.Start 

2.Declare the header file #include<stdio.h>

3.Inside the main function declare the keyword int for the variables number1 ,number2,number3.Use the Printf statement to display the text "Enter number1 and number2".

4.Use scanf and get the first number  and second number .For integer variable we have to use a format specifier "%d" .

Explanation:-

scanf:-Its used to get the user input from the user .

Since we are using two integer variable we are using two format specifiers which is of integer type i.e,"%d".

5.Use the number3 variable and subtract first number from second number .

6.Finally display the text "The subtraction of two numbers is " and print the number 3 variable.

7.Stop 

 Screenshot:-

1.Code Screenshot :-


2.Output Screenshot:-

2.Subtraction of two numbers using float.

#include <stdio.h>

int main()

{

      float number1,number2,number3;

     printf("Enter number 1 and number 2 "); 

     scanf("%f %f",&number1,&number2);

     number3=number1-number2;

     printf("The subtraction of two numbers is %f",number3);

      return 0;

}

Algorithm:-

1.Start 

2.Declare the header file #include<stdio.h>

3.Inside the main function declare the keyword float for the variables number1 ,number2,number3.Use the Printf statement to display the text "Enter number1 and number2".

4.Use scanf and get the first number  and second number .For float variable we have to use a format specifier "%f" .

Explanation:-

scanf:-Its used to get the user input from the user .

Since we are using two float variable we are using two format specifiers which is of float type i.e,"%f".

5.Use the number3 variable and subtract first number from second number .

6.Finally display the text "The subtraction of two numbers is " and print the number 3 variable.

7.Stop 

 Screenshot:-

1.Code Screenshot :-



2.Output Screenshot:-


3.Subtraction of two numbers using double datatype.

#include <stdio.h>

int main()

{

    printf("Enter number 1 and number 2 "); 

    double number1,number2,number3;

    scanf("%lf %lf",&number1,&number2);

    number3=number1-number2;

   printf("The subtraction of two numbers is %lf",number3);

    return 0;

}

Algorithm:-

1.Start 

2.Declare the header file #include<stdio.h>

3.Inside the main function declare the keyword double for the variables number1 ,number2,number3.Use the Printf statement to display the text "Enter number1 and number2".

4.Use scanf and get the first number  and second number .For double variable we have to use a format specifier "%lf" .

Explanation:-

scanf:-Its used to get the user input from the user .

Since we are using two double variable we are using two format specifiers which is of double type i.e,"%lf".

5.Use the number3 variable and subtract first number from second number .

6Finally display the text "The subtraction of two numbers is " and print the number 3 variable.

7.Stop 

 Screenshot:-

1.Code Screenshot :-


2.Output Screenshot:-


In the next blog we will see how to multiply two  numbers.