Please do this in C++ using only for loops, while loops, and do while loops. No
ID: 3908587 • Letter: P
Question
Please do this in C++ using only for loops, while loops, and do while loops. No arrays.
Use for loop, while loop, and do while loops to generate a table of decimal numbers, as well as the binary, octal, and hexadecimal equivalents of the decimal numbers in the range 1-256 Note: See Appendix for number systems The program should print the results to the Console without using any string formats Design Details: The Main program should prompt the user for input. The output is shown in the sample output below Note: To generate the binary numbers your code should use a while loop to generate the binary numbers, a "for" loop to generate the octal numbers and a "do .. while" to generate the hexadecimal numbers Sample Output: Enter the low number: Enter the high number: 10 Decima ? Binary Octal Hexadecimal 1 10 100 101 110 10 1000 1001 1010 10 12 ***Resetting low and high Low10, High-15 Decimal Binary 10 12 13 14 15 1010 1011 1100 1101 1110 Octal hexadecimal 12 13 14 15 16 17 Press any key to continue .. .Explanation / Answer
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int i,j,high,low,dnum,rem,bnum,rem1,onum,k,l,hexnum,hnum,m,rem2;
char ch;
cout<<"Enter the lowest number : ";
cin>>low;
cout<<"Enter the hightest number : ";
cin>>high;
//finding binary number
for(i=low;i<=high;i++)
{
dnum=i;
j=0;
bnum=0;
while(dnum!=0)
{
rem=dnum%2;
bnum+=rem*pow(10,j);
j++;
dnum=dnum/2;
}
//finding octal number
> l=0;
for(k=i;k!=0;k=k/8)
{
rem1=k%8;
onum+=rem1*pow(10,l);
l++;
}
//finding hexadeciaml number
hexnum=0;
hnum=i;
m=0;
do
{
rem2=hnum%16;
hexnum+=rem2*pow(10,m);
m++;
hnum=hnum/16;
}
while(hnum!=0);
switch(hexnum)
{
case 10:
ch='A';
break;
case 11:
ch='B';
break;
case 12:
ch='C';
break;
case 13:
ch='D';
break;
case 14:
ch='E';
break;
case 15:
ch='F';
break;
}
//printing the result
if(hexnum<=9)
{
cout<<i<<" "<<bnum<<" "<<onum<<" "<<hexnum<<endl;
}
else
{
cout<<i<<" "<<bnum<<" "<<onum<<" "<<ch<<endl;
}
}
return 0;
}