In this tutorial, you will learn how to write C++ program to find the average of three numbers using Arithmetic operators.

C++ Program to Find Average of Three Numbers

We shall read three numbers from user and compute the average. Formula to compute the average of three numbers is given below.

C++ Program - Average of Three Numbers

Algorithm

We shall use following algorithm to compute average of three numbers in C++.

  1. Start.
  2. Read first number to num_1.
  3. Read second number to num_2.
  4. Read third number to num_3.
  5. Initialize average with (num_1 + num_2 + num_3) /3.
  6. Stop.
ADVERTISEMENT

Program

In this example, we shall implement the above algorithm in C++. We shall read the numbers using cin, and compute the average using C++ Addition and C++ Division.

C++ Program

#include <iostream>
using namespace std;

int main() {
   int num_1;
   cout << "Enter num_1 : ";
   cin >> num_1;

   int num_2;
   cout << "Enter num_2 : ";
   cin >> num_2;

   int num_3;
   cout << "Enter num_3 : ";
   cin >> num_3;
   
   float average = (num_1 + num_2 + num_3) / 3;
   cout << "Average : " << average << endl;
}

We have taken float to store the average, because as we are dividing the sum of three numbers with 3, we may get a reminder left out if we take int to store the average.

Output

Enter num1 : 23
Enter num2 : 41
Enter num3 : 35
Average : 33

Conclusion

In this C++ Tutorial, we have written an algorithm and a C++ program to find average of three numbers.