Smallest number required to be added to M to make it divisible by N | C ++ program for the above approach ; Function to find the smallest number greater than or equal to N , that is divisible by k ; Function to find the smallest number required to be added to to M to make it divisible by N ; Stores the smallest multiple of N , greater than or equal to M ; Return the result ; Driver Code ; Given Input ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findNum ( int N , int K ) { int rem = ( N + K ) % K ; if ( rem == 0 ) return N ; else return N + K - rem ; } int findSmallest ( int M , int N ) { int x = findNum ( M , N ) ; return x - M ; } int main ( ) { int M = 100 , N = 28 ; cout << findSmallest ( M , N ) ; return 0 ; }