C++ Program to calculate the sum of two numbers. | C ++ प्रोग्राम दो संख्याओं की गणना करने के लिए।






















C++ Program to calculate the sum of two numbers.

Let see the program add two numbers.


Example:
  1. Declare three variables they are integer or float data types x, y,z.

  2. Declare one int data type and one float datatype, then store float data type.

  3. Declare two float data type, then store float data type.

  4. Declare two integer data types, then store integer data type.

  5. Input x=10,y=20

  6. Then z=x+y

  7. Sum two numbers z=30.





#include <iostream> using namespace std; int main() { int x; float y,z; cout<<"Enter x value :"; cin>>x; cout<<"Enter y value :"; cin>>y; z=x+y; cout<<" Sum of two numbers :"<<z<<endl; return 0; }

Output:

Enter x value :31 Enter y value :31.36 Sum of two numbers :62.36



#include <iostream> using namespace std; int main() { float x,y,z; cout<<"Enter x value :"; cin>>x; cout<<"Enter y value :"; cin>>y; z=x+y; cout<<" Sum of two numbers :"<<z<<endl; return 0; }

Output:

Enter x value :31.10 Enter y value :36.10 Sum of two numbers :67.2


#include <iostream> using namespace std; int main() { int x,y,z; cout<<"Enter x value :"; cin>>x; cout<<"Enter y value :"; cin>>y; z=x+y; cout<<" Sum of two numbers :"<<z<<endl; return 0; }

Output:

Enter x value :31 Enter y value :36 Sum of two numbers :67