- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C/C++ Program to Find reminder of array multiplication divided by n ?
Here we will see how to calculate the remainder of array multiplication after dividing the result by n. The array and the value of n are supplied by the user. Suppose the array is like {12, 35, 69, 74, 165, 54} so the multiplication will be (12 * 35 * 69 * 74 * 165 * 54) = 19107673200. Now if we want to get the remainder after diving this by 47 it will be 14.
As we can see this problem is very simple. we can easily multiply the elements then by using modulus operator, it can get the result. But the main problem is when we calculate the multiplication, it may exceed the range of integer, or long also. So it may return some invalid results. To overcome this problem, we will follow this process.
Algorithm
multiplyRemainder(arr, size, n)
begin mul := 1 for i in range 0 to size – 1, do mul := (mul * (arr[i] mod n)) mod n done return mul mod n end
Example
#include<iostream> using namespace std; int multiplyRemainder(int arr[], int size, int n){ int mul = 1; for(int i = 0; i<size; i++){ mul = (mul * (arr[i] % n)) % n; } return mul % n; } int main(){ int arr[6] = {12, 35, 69, 74, 165, 54}; int size = 6; int n = 47; cout << "Remainder: " << multiplyRemainder(arr, size, n); }
Output
Remainder: 14
- Related Articles
- C/C++ Program to Find the reminder of array multiplication divided by n?
- Find reminder of array multiplication divided by n in C++
- Java Program to find reminder of array multiplication divided by n
- Python Program for Find reminder of array multiplication divided by n
- C++ program for multiplication of array elements
- Find the number which when divided by 56 gives a quotient 108 and reminder 39
- Program to find remainder when large number is divided by 11 in C++
- Program to find remainder when large number is divided by r in C++
- C program to print multiplication table by using for Loop
- C++ program to find perfect array of size n whose subarray is a good array
- C program to find type of array entered by the user.
- C++ Program to Generate Multiplication Table
- C++ Program to Perform Matrix Multiplication
- Count divisors of array multiplication in C++
- C++ Program to Implement Booth’s Multiplication Algorithm for Multiplication of 2 signed Numbers

Advertisements