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
Clarification:  3) 11 (3
                                – 9
                           ———
                                  2 -> The rest
                          ———-

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

Strategy: The issue may be solved by utilizing 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 offers 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 most important()

{

    int Num1 = 11;

    int Num2 = 3;

  

    

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

    return 0;

}

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

Leave a Reply