CPP code for Subtraction of two numbers



Subtraction OF TWO NUMBERS


SIMPLE CPP LANGUAGE CODE FOR SUBTRACTION OF TWO NUMBERS:

#include<iostream.h>
#include<conio.h>
void main()
{int a, b, c;//we take two integer value
cout<<"Enter the number :";//use to print the letter, character
cin>>a>>b;//use to accept number
c=a-b;//arithmetic logical operation, formula
cout<<"Ans="<<c; /*use to perform operation and display answer*/
getch();
}

And save with extension .cpp
for eg.
subtract.cpp// subtract is the name of the file and .cpp is extension of file.
           In the above example, we can add integer numbers not fractional numbers. For example when output screen comes type two numbers like 45 and press enter then type next numbers like 60 then press enter the answer will be displayed on the output screen.
---------------------------------------------------------------------------------------
OUTPUT:
Enter the number: 45
                              60
Ans=105

            This code is for integer numbers if you want to add fractional numbers then in above code small changes is there i.e.in the place of int type float. For subtraction of fractional numbers the code is as follow:

SUBTRACTION OF TWO FRACTIONAL NUMBERS:
#include<iostream.h>
#include<conio.h>
void main()
{flaot a, b, c;//we take two fractional value
cout<<"Enter the number :";//use to print the letter, character
cin>>a>>b;//use to  accept number
c=a-b;//arithmetic logical operation, formula
cout<<"Ans="<<c; /*use to perform operation and display answer*/
getch ();
}
---------------------------------------------------------------------------------------
OUTPUT:
Enter the number: 4.5
                              6.7
Ans=11.2


     In the previous blog, I was say that many types of comment is there in that other type is
/*        comment         */.This is used to give the multiline comments for example.
cout<<"Ans="<< c;/*use to perform operation and display answer*/

           I hope you like my blog so if any queries are there then write in the comment box. I will solve it. Friends in the next blog I will teach you another program.

CPP code for Subtraction of two numbers CPP code for Subtraction of two numbers Reviewed by Amit Waghmare on July 07, 2019 Rating: 5

No comments: