Sunday, September 11, 2022
HomeWordPress DevelopmentThe rest Analysis - GeeksforGeeks

The rest Analysis – GeeksforGeeks


View Dialogue

Enhance Article

Save Article

Like Article

View Dialogue

Enhance Article

Save Article

Like Article

Given two optimistic integers Num1 and Num2, the duty is to search out the rest when Num1 is split by Num2.

Examples:

Enter:  Num1 = 11, Num2 = 3
Output: 2
Rationalization:  3) 11 (3
                                – 9
                           ———
                                  2 -> The rest
                          ———-

Enter: Num1 = 15, Num2 = 3
Output: 0

Method: The issue will be solved through the use of the modulus operator.

  • Modulus operator returns the rest, if we write a % b, it returns the rest when a is split by b the place b != 0. If b = 0, then it provides Runtime Error,
    • Math error in C++, [Math error: Attempted to divide by Zero]
    • ZeroDivisionError in Python, [ZeroDivisionError: integer division or modulo by zero]
    • ArithmeticException in Java [ArithmeticException: / by zero]

Beneath is the implementation of the above strategy:

C++

  

#embrace <bits/stdc++.h>

utilizing namespace std;

  

int remedy(int Num1, int Num2)

{

    return Num1 % Num2;

}

  

int important()

{

    int Num1 = 11;

    int Num2 = 3;

  

    

    cout << remedy(Num1, Num2) << endl;

    return 0;

}

Time Complexity: O(1)
Auxiliary Area: O(1)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments