#include<iostream>
using namespace std;
void d2b()
{
long decimal, d12, rem, x=1, sum=0;
cout <<"pick a decimal integer: "; cin>> decimal;
d12= decimal;
while(decimal>0)
{
rem= decimal % 2;
sum+= ( x*rem );
decimal/= 2;
x*= 10;
}
cout <<"\n\nBinary of " <<d12 <<" is: " <<sum <<endl <<endl;
}
void b2d()
{
long binary, m35, rem, y=1, sum=0;
cout <<"pick a binary number: "; cin>> binary;
m35= binary;
while(binary !=0)
{
rem= binary % 10;
sum+= (y*rem);
binary/=10;
y*=2;
}
cout <<"\n\ndecimal of " <<m35 <<" is: " <<sum <<endl <<endl;
}
int main()
{
char c;
cout <<"make your pick: \n";
cout <<"a. decimal to Binary.\n";
cout <<"b. Binary to decimal.\npick: ";
cin>> c;
switch(c)
{
case 'a': d2b(); break;
case 'b': b2d(); break;
}
}
using namespace std;
void d2b()
{
long decimal, d12, rem, x=1, sum=0;
cout <<"pick a decimal integer: "; cin>> decimal;
d12= decimal;
while(decimal>0)
{
rem= decimal % 2;
sum+= ( x*rem );
decimal/= 2;
x*= 10;
}
cout <<"\n\nBinary of " <<d12 <<" is: " <<sum <<endl <<endl;
}
void b2d()
{
long binary, m35, rem, y=1, sum=0;
cout <<"pick a binary number: "; cin>> binary;
m35= binary;
while(binary !=0)
{
rem= binary % 10;
sum+= (y*rem);
binary/=10;
y*=2;
}
cout <<"\n\ndecimal of " <<m35 <<" is: " <<sum <<endl <<endl;
}
int main()
{
char c;
cout <<"make your pick: \n";
cout <<"a. decimal to Binary.\n";
cout <<"b. Binary to decimal.\npick: ";
cin>> c;
switch(c)
{
case 'a': d2b(); break;
case 'b': b2d(); break;
}
}
No comments:
Post a Comment