Write a function that computes and displays a table of negative powers of two (2-1, 2-2 …..) as both common fractions and decimals.
The range of powers printed should be determined by the function’s input arguments. Test your function using a driver.
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
void Power(int a, int b);
int a, b;
cout << "Enter Upper value for power of 2 = ";
cin >> a;
cout << "Enter Lower value for power of 2 = ";
cin >> b;
Power(a, b);
getche();
return 0;
}
void Power(int a, int b)
{
cout << endl << "Power of 2 \t Fraction \t Decimal Values\n";
for(int i=a; i>=b; i--)
cout << " " << i << "\t\t 1/" << pow(2,-i) << "\t\t\t"
<< pow(2,i) << endl;
}
No comments:
Post a Comment