I am trying to write code for converting Decimal number to Hexadecimal number by using Recursion n I successfully did it.
But my out was printing more than once.
For example:
Enter Decimal Number :590
Hexadecimal Number :24E24E24E24E
but the output should be 24E,i dont understand why it was printing more then once
can an one help me
this is my code
#include <iostream>
using namespace std;
//function to convert
void conv_decimalNumber_to_hexadecimalNumber(int,int[]);
void main()
{
int decNum,decNumRem[50]; //i took decNumRem to hold remainder
cout << endl << "Convert Decimal Number to Hexadecimal Number";
cout << endl << "Ender Decimal Number:";
cin >> decNum;
cout << endl << "Hexadecimal Number:";
conv_decimalNumber_to_hexadecimalNumber(decNum,decNumRem);
cout << endl;
system("PAUSE");
}
int i=0;
void conv_decimalNumber_to_hexadecimalNumber(int decNum,int r[])
{
if(decNum > 0)
{
r[i]=decNum%16;
i++;
decNum = decNum/16;
conv_decimalNumber_to_hexadecimalNumber(decNum,r);
}
for(int x=(i-1); x>=0;--x)
{
if(r[x] > 9)
{
switch (r[x])
{
case 10 :
{
cout << "A";
break;
}
case 11 :
{
cout << "B";
break;
}
case 12 :{
cout << "C";
break;
}
case 13 :
{
cout << "D";
break;
}
case 14 :
{
cout << "E";
break;
}
case 15 :
{
cout << "F";
break;
}
}
}
else
{
cout << r[x];
}
}
}
hope some one will help .... :-)
This post has been edited by forurup: 29 January 2010 - 12:07 AM

New Topic/Question
Reply



MultiQuote





|