top of page

2

C/C++ Program for Efficient way to multiply with 7.

program solution

# include<stdio.h>

 

int multiplyBySeven(unsigned int n)

    /* Note the inner bracket here. This is needed because precedence of '-' operator is higher than '<<' */

    return ((n<<3) - n);

}

 

/* Driver program to test above function */

int main()

{

    unsigned int n = 4;

    printf("%u", multiplyBySeven(n));

 

    getchar();

    return 0;

}

Output

28

bottom of page