# include <iostream.h> # include <fstream.h> # include <string.h> # include <stdlib.h> # include <conio.h> void hexadecimal(long); int main( ) { clrscr( ); fstream file(\"CP-01.txt\",ios::in|ios::nocreate); if(!file) { cout<<\"\\n Unable to open the input file.\"<<endl; cout<<\"\\n Press any key to exit.\"; getch( ); exit(EXIT_FAILURE); } long decimal_number=0; char Decimal_number[10]={NULL}; do { strset(Decimal_number,NULL); file.getline(Decimal_number,6); decimal_number=atol(Decimal_number); if(decimal_number==0) break; hexadecimal(decimal_number); } while(1); file.close( ); getch( ); return 0; } //-------------------------- hexadecimal(long) -------------------------// void hexadecimal(long number) { int qutiont=0; int remainder=0; char Hex_digit[5]={NULL}; char Hexadecimal_number[10]={NULL}; do { qutiont=number/16; remainder=number%16; number=qutiont; if(remainder<10) { strset(Hex_digit,NULL); itoa(remainder,Hex_digit,10); strcat(Hexadecimal_number,Hex_digit); } else { switch (remainder) { case 10 : strcat(Hexadecimal_number,\"A\"); break; case 11 : strcat(Hexadecimal_number,\"B\"); break; case 12 : strcat(Hexadecimal_number,\"C\"); break; case 13 : strcat(Hexadecimal_number,\"D\"); break; case 14 : strcat(Hexadecimal_number,\"E\"); break; case 15 : strcat(Hexadecimal_number,\"F\"); break; } } } while(number>0); strrev(Hexadecimal_number); cout<<Hexadecimal_number<<endl; }