# Sum of two numbers modulo M

Given three numbers A, B, and M. The task is to print the sum of A and B under modulo M.

Examples:

```Input: a = 10, b = 20, m = 9
Output: 0
10+20 = 30 % 9 = 0

Input: a = 100, b = 13, m = 107
Output: 6
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: Add the two given numbers A and B and print their sum under modulo M.

Below is the implementation of the above approach:

## C++

 `// C++ program for sum of two ` `// numbers modulo M ` `#include ` `using` `namespace` `std; ` ` `  `// Function to return summation mod m ` `int` `sum(``int` `a, ``int` `b, ``int` `m) ` `{ ` `    ``// add two numbers ` `    ``int` `s = a + b; ` ` `  `    ``// do a mod with m ` `    ``s = s % m; ` ` `  `    ``return` `s; ` `} ` ` `  `// Driver Code ` `int` `main() ` `{ ` `    ``int` `a = 20, b = 10, m = 3; ` `    ``cout << sum(a,b,m); ` `    ``return` `0; ` `} `

## Java

 `// java program for addition of ` `// two numbers modulo m ` ` `  `import` `java.io.*; ` ` `  `class` `GFG { ` ` `  `    ``static` `int` `sum(``int` `a, ``int` `b, ``int` `m) ` `    ``{ ` `        ``int` `s = a + b; ` `        ``s = s % m; ` `        ``return` `s; ` `    ``} ` `    ``// Driver Code ` `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` `        ``int` `a = ``10``, b = ``20``, m = ``3``; ` `        ``System.out.println(``"The sum = "` `+ sum(a, b, m)); ` `    ``} ` `} `

## Python

 `# Python program for addition of  ` `# two numbers modulo m ` `def` `summ(a, b, m):  ` `    ``s ``=` `a ``+` `b  ` `    ``s ``=` `s ``%` `m  ` `    ``return` `s  ` `  `  `# Driver Code    ` `a ``=` `20` `b ``=` `10`  `m ``=` `3`  `print` `summ(a, b, m)  `

## C#

 `// C# program for addition of ` `// two numbers modulo m ` `using` `System; ` ` `  `class` `GFG { ` ` `  `    ``static` `int` `sum(``int` `a, ``int` `b, ``int` `m) ` `    ``{ ` `        ``int` `s = a + b; ` `        ``s = s % m; ` `        ``return` `s; ` `    ``} ` `     `  `    ``// Driver Code ` `    ``public` `static` `void` `Main() ` `    ``{ ` `        ``int` `a = 10, b = 20, m = 3; ` `        ``Console.Write(``"The sum = "` `+ sum(a, b, m)); ` `    ``} ` `} ` ` `  `// This code is contributed by  ` `// Smitha Dinesh Semwal `

## PHP

 ` `

Output:

```The sum = 0
```

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.