- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Fast average of two numbers without division in C++

In this problem, we are given two numbers A and B. Our task is to create a program to calculate the *Fast average of two numbers without division. *

## Let’s take an example to understand the problem,

**Input: **A = 34 B = 54

**Output: **44

**Solution Approach: **

Normally, the average is calculated by adding two numbers and then divide it by 2. This requires division but we need to find the average without using division. This can be done using right shift operator >> and shift the binary expansion instead of using division operator.

## Program to illustrate the working of our solution,

## Example

#include <iostream> #include <stdio.h> using namespace std; int calcAvgWODiv(int A, int B) { int average = (A + B) >> 1; return average; } int main() { int A = 123 , B = 653; cout<<"The average of the number is "<<calcAvgWODiv(A, B); return 0; }

## Output −

The average of the number is 388

- Related Questions & Answers
- Addition of two numbers without propagating Carry?
- Splitting array of numbers into two arrays with same average in JavaScript
- Average of Squares of Natural Numbers?
- Average of Squares of n Natural Numbers?
- Average of a stream of numbers in C++
- 8085 program to sum of two 8 bit numbers without carry
- Average of first n odd naturals numbers?
- Average of first n even natural numbers?
- What is the division of binary numbers in Computer Architecture?
- Division without using ‘/’ operator in C++ Program
- Subtracting two numbers without using the (-) sign JavaScript
- C Program to find sum of two numbers without using any operator
- Find the Sum of two Binary Numbers without using a method in C#?
- Find HCF of two numbers without using recursion or Euclidean algorithm in C++
- Realtime moving average of an array of numbers in JavaScript

Advertisements