A Program to Add Two Floating Numbers

In this example, we are giving a program to add two floating numbers which are given by the user.


Program to add two floating numbers:

  1. #include <iostream>
  2. using namespace std;
  3. float main()
  4. {
  5. float first_number, second_number, sum;
  6. cout << "Enter two floating point number: ";
  7. // Two floating number entered by user stored
  8. cin >> first_number >> second_number;
  9. // Sum of the two numbers stored in the variable sum
  10. sum = first_number + second_number;
  11. // Displaying the value of sum
  12. cout << first_number << "+" << second_number << "=" << sum;
  13. return 0;
  14. }

Output:

Enter two floating point number: 7.2
17.5
7.2 + 17.5 = 24.7