Write a program that will calculate the log base 2 of an int
Write a program that will calculate the log base 2 of an integer. The log base 2 can be easily calculated by counting the number of times you have to shift a number to the right before it is one. #include using namespace std; int main(int argn, char *argv[]) {int number, log; cout > number; _asm {//Calculate the logz of number and store the result in log} cout
Solution
#include<iostream>
#include<cmath>
using namespace std;
int main(int argc, char const *argv[])
{
int number,log;
cout<<\"Enter a number\ \";
cin>>number;
_asm
{
log=log(number)/log(2);
}
cout<<\"Logarithm is \"<<log<<endl;
return 0;
}
===========================================
Output:
Enter a number
3
Logarithm is 1.584962501
