CPP code for Addition of two numbers



ADDITION OF TWO NUMBERS


SIMPLE CPP LANGUAGE CODE FOR ADDITION 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.
add.cpp//add 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 the output screen comes type two numbers like 2 and press enter then type next numbers like 6 then press enter the answer will be displayed on the output screen.
            This code is for integer numbers, if we want to add fractional numbers then in above code small changes is there i.e.in the place of int type float.For addition of fractional numbers the code is as follow:

ADDITION 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 ();
}

     In the previous blog, I said 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 Addition of two numbers CPP code for Addition of two numbers Reviewed by Amit Waghmare on July 03, 2019 Rating: 5

No comments: