Credits

Sunday, February 22, 2009

Another Single Array Sample Program

Conversion of number systems may be a little confusing but not at all impossible. Use the codes below as basis for a more improved conversion from decimal to hexadecimals.



[+/-] show/hide



/* program to convert decimals to hexadecimals or base 16 */
# include stdio.h /* enclose the library in <> */
main()
{
float quofloat, decimal;
int dec, quotient;
int ctr;
int converted[10];
clrscr();

printf("Enter decimal digits : ");
scanf("%",&decimal);

quofloat=decimal;

ctr=0;
do
{
quofloat=quofloat/16;
quotient=quofloat%16;
printf("%.2f division by 16\n",quofloat);
converted[ctr]=quotient;
printf(" remainder: %d\n ",converted[ctr]);
ctr=ctr+1;
}
while(quofloat>=1);
getch();
}

Translate this to C++.

AddThis