- 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 the reminder of array multiplication divided by n?
Array multiplication we will find the product of all elements of the given array. and then according to the problem, we will divide the product with the number n. let's take an example −
Input: arr[] = { 12, 35, 69, 74, 165, 54}; N = 47 Output: 14
Explanation
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 dividing this by 47 it will be 14.
First multiple all the number then take % by n then find the reminder, But in this approach, if the number is maximum of 2^64 then it gives the wrong answer.
Example
#include <stdio.h> int main() { int arr[] = { 12, 35, 69, 74, 165, 54}; int len = 6; int n = 47 ; int mul = 1; for (int i = 0; i < len; i++) mul = (mul * (arr[i] % n)) % n; printf("the remainder is %d", (mul%n)); return 0; }
Output
the remainder is 14
- Related Articles
- C/C++ Program to Find 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
- C program to find type of array entered by the user.
- 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 Generate Multiplication Table
- C++ Program to Perform Matrix Multiplication
- C++ Program to find kth Smallest Element by the Method of Partitioning the Array
- Count divisors of array multiplication in C++

Advertisements