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 <stdio.h>
  2. float main()
  3. {
  4. float first_number, second_number, sum;
  5. printf("Enter two floating point number: ");
  6. // Two floating number entered by user stored
  7. scanf("%lf %lf", &first_number, &second_number);
  8. // Sum of the two numbers stored in the variable sum
  9. sum = first_number + second_number;
  10. // Displaying the value of sum
  11. printf("%lf + %lf = %.2lf", first_number, second_number, sum);
  12. return 0;
  13. }

Output:

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