#include<stdio.h>
#include<conio.h>
#include<math.h>
int
D2B(int);
int
D2O(int);
int
D2H(int);
main()
{
int ch,num;
clrscr();
while(1)
{
printf("\n1.Decimal 2 Binary.");
printf("\n2.Decimal 2 Octal.");
printf("\n3.Decimal 2 Hexa.");
printf("\n4.Exit.");
printf("\nEnter your Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
clrscr();
printf("\nEnter any Decimal
number:");
scanf("%d",&num);
D2B(num);
//calling functione
break;
case 2:
clrscr();
printf("\nEnter any Decimal
number:");
scanf("%d",&num);
D2O(num); //calling function
break;
case 3:
clrscr();
printf("\nEnter any Decimal
number:");
scanf("%d",&num);
D2H(num); //calling function
break;
case 4:
exit(0);
}
}
getch();
}
int
D2B(int dec) //decimal to binary
{
int bin=0,*bin_arr,count=0;
while(dec>0)
{
bin=dec%2;
dec/=2;
*(bin_arr+count)=bin;
count++;
}
printf("\nBINARY=");
while(count > 0)
{
--count;
printf("%d",*(bin_arr+count));
}
return 0;
}
int
D2O(int dec) //decimal to octal
{
int oct=0,*oct_arr,count=0;
while(dec>0)
{
oct=dec%8;
dec/=8;
*(oct_arr+count)=oct;
count++;
}
printf("\nOCTAL=");
while(count > 0)
{
--count;
printf("%d",*(oct_arr+count));
}
return 0;
}
int
D2H(int dec) //decimal to hexa
{
int hexa=0,*hexa_arr,count=0;
while(dec>0)
{
hexa=dec%16;
dec/=16;
*(hexa_arr+count)=hexa;
count++;
}
printf("\nHEXA=");
while(count > 0)
{
--count;
switch(*(hexa_arr+count))
{
case 10:
printf("A");
break;
case 11:
printf("B");
break;
case 12:
printf("C");
break;
case 13:
printf("D");
break;
case 14:
printf("E");break;
case 15:
printf("F");break;
default:
printf("%d",*(hexa_arr+count));
break;
}
}
}