UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C++ Program to find Average of two numbers

c++ program for how to find average of two numbers

by Krishna viswambharan


Posted on 20 Jul 2018 Category: C plus plus Views: 54

Edited on 26 Jul 2018


Average of two numbers

This section explains a simple c++ program to read two numbers from the keyboard and display their average on the screen. Source code and output for the program is shown below.

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
   float n1,n2,sum,average;
   cout<”Enter the first number :”;
   cin>>n1;          //Read numbers from keyboard
   cout<”Enter the second number :”;
   cin>>n2;
   sum=n1+n2;
   average=sum/2;
   cout<<”Sum=”<<sum<<”\n”;
   cout<<”Average =”<<average<<”\n”;
   return 0;
   getch();
}

OUTPUT

NOTE: some old versions of c++ use header  file <iostream.h>. so we should use iostream.h if the compiler does not support ANSI C++ features.

 

 



Leave a Comment:


Advertisement