Quotient and remainder dividing by 2 ^ k ( a power of 2 ) | CPP to find remainder and quotient ; function to print remainder and quotient ; print Remainder by n AND ( m - 1 ) ; print quotient by right shifting n by ( log2 ( m ) ) times ; driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; void divide ( int n , int m ) { cout << " Remainder ▁ = ▁ " << ( ( n ) & ( m - 1 ) ) ; cout << " Quotient = " } int main ( ) { int n = 43 , m = 8 ; divide ( n , m ) ; return 0 ; }