Programs

C++ Program to Add Two Numbers

Here’s a simple C++ program to add two numbers, which can be compiled and executed using Turbo C++:

#include <iostream.h>
#include <conio.h>

void main() {
    clrscr(); // Clear screen function for Turbo C++

    float num1, num2, sum;

    cout << "Enter first number: ";
    cin >> num1;

    cout << "Enter second number: ";
    cin >> num2;

    sum = num1 + num2;

    cout << "The sum of " << num1 << " and " << num2 << " is: " << sum;

    getch(); // Wait for a key press in Turbo C++
}

To compile and run this program in Turbo C++:

  1. Open Turbo C++.
  2. Create a new source file or open an existing one.
  3. Copy and paste the above code.
  4. Compile the program (usually by pressing Alt + F9).
  5. Run the compiled program (usually by pressing Ctrl + F9).
  6. Enter two numbers to see their sum.

Note: The clrscr() and getch() functions are specific to the Turbo C++ compiler and won’t work on most modern C++ compilers. If you’re using a modern compiler, you might want to exclude these functions.