Multiple of x closest to n | CPP program to calculate the smallest multiple of x closest to a given number ; Function to calculate the smallest multiple ; driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int closestMultiple ( int n , int x ) { if ( x > n ) return x ; n = n + x / 2 ; n = n - ( n % x ) ; return n ; } int main ( ) { int n = 9 , x = 4 ; printf ( " % d " , closestMultiple ( n , x ) ) ; return 0 ; }