1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
const int a = 10, A =10, b = 11,B = 11,c = 12, C = 12, d =13, D =13, e = 14, E = 14, f = 15 , F = 15;
const int size = 10;
char chose;
double Decimal,Hex,counter = 0;
char ar[size];
for ( counter ; counter < size ; counter ++ )
{
cout << "Enter Your Hexa-Decimal Number : ";
cin >> Hex;
counter = Hex;
cout << "\nDo You Want to show the addition\n Hexa-Decimal number in Decimal <y/n> : ";
cin >> chose;
if ( chose == 'y' || chose == 'Y' )
{
if ( counter == 0 )
{
Decimal = ( counter * ( pow(16,0) ) );
}
else if ( counter == 1 )
{
Decimal = ( ( counter * ( pow(16,1) ) ) + ( counter * ( pow(16,0) ) ) );
}
else if ( counter == 2 )
{
Decimal = ( ( counter * ( pow(16,2) ) ) + ( counter * ( pow(16,1) ) ) + ( counter * ( pow(16,0) ) ) );
}
else if ( counter == 3 )
{
Decimal = ( ( counter * ( pow(16,3) ) ) + ( counter * ( pow(16,2) ) ) + ( counter * ( pow(16,1) ) ) + ( counter * ( pow(16,0) ) ) );
}
else if ( counter == 4 )
{
Decimal = ( ( counter * ( pow(16,4) ) ) + ( counter * ( pow(16,3) ) ) + ( counter * ( pow(16,2) ) ) + ( counter * ( pow(16,1) ) ) + ( counter * ( pow(16,0) ) ) );
}
else if ( counter == 5 )
{
Decimal = ( ( counter * ( pow(16,5) ) ) + ( counter * ( pow(16,4) ) ) + ( counter * ( pow(16,3) ) ) + ( counter * ( pow(16,2) ) ) + ( counter * ( pow(16,1) ) ) + ( counter * ( pow(16,0) ) ) );
}
else if ( counter == 6 )
{
Decimal = ( ( counter * ( pow(16,6) ) ) + ( counter * ( pow(16,5) ) ) + ( counter * ( pow(16,4) ) ) + ( counter * ( pow(16,3) ) ) + ( counter * ( pow(16,2) ) ) + ( counter * ( pow(16,1) ) ) + ( counter * ( pow(16,0) ) ) );
}
else if ( counter == 7 )
{
Decimal = ( ( counter * ( pow(16,7) ) ) + ( counter * ( pow(16,6) ) ) + ( counter * ( pow(16,5) ) ) + ( counter * ( pow(16,4) ) ) + ( counter * ( pow(16,3) ) ) + ( counter * ( pow(16,2) ) ) + ( counter * ( pow(16,1) ) ) + ( counter * ( pow(16,0) ) ) ); }
else if ( counter == 8 )
{
Decimal = ( ( counter * ( pow(16,8) ) ) + ( counter * ( pow(16,7) ) ) + ( counter * ( pow(16,6) ) ) + ( counter * ( pow(16,5) ) ) + ( counter * ( pow(16,4) ) ) + ( counter * ( pow(16,3) ) ) + ( counter * ( pow(16,2) ) ) + ( counter * ( pow(16,1) ) ) + ( counter * ( pow(16,0) ) ) );
}
else if ( counter == 9 )
{
Decimal = ( ( counter * ( pow(16,9) ) ) + ( counter * ( pow(16,8) ) ) + ( counter * ( pow(16,7) ) ) + ( counter * ( pow(16,6) ) ) + ( counter * ( pow(16,5) ) ) + ( counter * ( pow(16,4) ) ) + ( counter * ( pow(16,3) ) ) + ( counter * ( pow(16,2) ) ) + ( counter * ( pow(16,1) ) ) + ( counter * ( pow(16,0) ) ) );
}
else
{
cout << "Addition Overflow\n";
break;
}
}
else
{
cout << counter << "in Hexa-Decimal = " << Decimal << " in Decimal\n";
break;
}
}
return 0;
|