Monday, 3 September 2012

  • WAP to Intput a number and print its Binary and Hexa-decimal Equivalent.
#include <stdio.h>
#include <conio.h>
void main()
{
    int bind,hind,i,org,no,b[40],h[40];
    printf("Enter a number");
    scanf("%d",&no);
    org=no;
    bind=-1;
//Coverting to binary number
    while(no>0)
    {
        bind++;
        b[bind]=no%2;
        no=no/2;
        }
        hind=-1;
        no=org;
        //Coverting to Hexa-decimal number
        while(no>0)
        {
            hind++;
            h[hind]=no%16;
            no=no/16;
            }
//Printing binary number
            for(i=bind;i>=0;i--)
            printf("%d",b[i]);
            printf("\n");
//Printing hexa-decimal
            for(i=hind;i>=0;i--)
            {
                if(h[i]<=9)
                printf("%d",h[i]);
                else
                printf("%c",(char)h[i]+55);
                  }
                  }

No comments:

Post a Comment