Friday 7 September 2012

Array030

Input a decimal number and write a program to convert this number into hexadecimal number.

#include <stdio.h>
#include <conio.h>

void main ( )
{
           int        n, hex[16], i = 0, d;
           clrscr ( );
                                   
           printf ("\n\t\t\t Enter a number...........:"); scanf ("%d", &n);
                                 
           while ( n > 0 )
           {                           
                         d = n % 16;
                         n = n / 16;
                         hex[i++] = d;
           }
                                                          
           printf("\n\n\n\t\t\t The Hexadecimal value = ");
           for ( i = i - 1; i >= 0; i-- )
           {                                            
                         if ( hex[i] >= 0 && hex[i] <= 9 )
                         {                                                   
                                            printf("%d", hex[i] );
                         }                                                  
                         else
                         {                                           
                                             printf("%c",hex[i]+55);
                         }
           }
           getch ( );
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...