Search This Blog

Translate

c program to accept a number and convert it in to binary ,desimal, hexa desimal ,octal using switch case

c program to accept a number and convert it in to binary ,decimal, hex a decimal ,octal using switch case



#include
#include
void main()
{
  int dec;
  int b[33],i=0;
  char f;
  clrscr();
  printf("\n Enter the format h,o,b:");
  scanf("%c",&f);
  printf("\n Enter the no to convert:");
  scanf("%d",&dec);

  switch(f)
  {
   case 'h':printf("\n Hexadecimal=%x",dec);
          break;
   case 'o':printf("\n Octal=%o",dec);
          break;
   case 'b':
        printf("\n binary=");
        while(dec>0)
         { if(dec%2==0)
           {
        b[i]=0;
        i++;}
           else
           {
         b[i]=0;
         i++;
        }
          dec=dec/2;
         }

          break;
   default:printf("\n Enter only h,b,o:");

  }

  getch();
}

C Program example List

Google+ Badge