- Related Questions & Answers
- Maximum subarray sum modulo m in C++
- Count of numbers satisfying m + sum(m) + sum(sum(m)) = N in C++
- Take two numbers m and n & return two numbers whose sum is n and product m in JavaScript
- Sum of two large numbers in C++
- Sum of the natural numbers (up to N) whose modulo with K yield R in C++
- Sum of even numbers from n to m regardless if n<m or n>m JavaScript
- Sum of the multiples of two numbers below N in C++
- How to find the Sum of two Binary Numbers using C#?
- Minimum sum of two numbers formed from digits of an array in C++
- Sum of Square Numbers in C++
- Maximum difference between two subsets of m elements in C
- Sum of sum of first n natural numbers in C++
- Max sum of M non-overlapping subarrays of size K in C++
- Print all integers that are sum of powers of two given numbers in C++
- C Program to find sum of two numbers without using any operator

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

In this problem, we are given three numbers a, b, and M. our task is to create a program to find the sum of two numbers modulo M.

Input: a = 14 , b = 54, m = 7 Output: 5 Explanation: 14 + 54 = 68, 68 % 7 = 5

To solve this problem, we will simply add the numbers a and b. And then print the remainder of the sum when divided by M.

Program to illustrate the working of our solution,

#include <iostream> using namespace std; int moduloSum(int a, int b, int M) { return (a + b) % M; } int main() { int a = 35, b = 12, M = 7; cout<<"The sum modulo is "<<moduloSum(a,b,M); return 0; }

The sum modulo is 5

Advertisements