
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Multiply a number by 15 without using * and / operators in C++
We can using left shift (<<) operator to multiply with 15. If we left shift 1, then we are multiplying it with 2.
If we left shift the given number with 4, then we will get the 16 * n. Subtracting the given number from 16 * n will result in 15 * n.
Or
We can also divide it as 8 * n + 4 * n + 2 * n + n. You can easily multiply the powers of 2 using left shift.
Algorithm
- Initialise the number n.
- Find the n << 4 to get 16 * n.
- Subtract n from the above result.
- Return the final answer.
Implementation
Following is the implementation of the above algorithm in C++
#include <bits/stdc++.h> using namespace std; long long getMultiplicationResult(long long n) { return (n << 4) - n; } int main() { long long n = 15; cout << getMultiplicationResult(n) << endl; return 0; }
Output
If you run the above code, then you will get the following result.
225
- Related Articles
- How to multiply a given number by 2 using Bitwise Operators in C#?
- Check if a number is multiple of 5 without using / and % operators in C++
- Write you own Power without using multiplication(*) and division(/) operators in C Program
- Find maximum in an array without using Relational Operators in C++
- Find minimum in an array without using Relational Operators in C++
- How to sum two integers without using arithmetic operators in C/C++?
- How to sum two integers without using arithmetic operators in C/C++ Program?
- Multiply any Number with using Bitwise Operator in C++
- Check if n is divisible by power of 2 without using arithmetic operators in Python
- Check if a large number is divisibility by 15 in C++
- Print a number 100 times without using loop, recursion and macro expansion in C
- Check if a number is positive, negative or zero using bit operators in C++
- How to find the missing number and the repeated number in a sorted array without using any inbuilt functions using C#?
- Least Operators to Express Number in C++
- How to multiply all values in a list by a number in R?

Advertisements