/*assignment number=2 */
/* write a c program for menu driven program for decimal to octal & decimal to hexadecimal*/
#include<stdio.h>
#include<conio.h>
void main()
{
int dec,choice;
int dec_to_octal(int);
int dec_to_hexadec(int);
clrscr();
printf("\n1 :convert decimal to octal");
printf("\n2 :convert decimal to hexadecimal");
printf("\nenter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("enter the decimal number :");
scanf("%d",&dec);
dec_to_octal(dec);
break;
case 2: printf("enter the decimal number :");
scanf("%d",&dec);
dec_to_hexadec(dec);
break;
}
getch();
}
int dec_to_octal(int dec)
{
int r[10],i=0;
while(dec>0)
{
r[i]=dec%8;
i++;
dec=dec/8;
}
printf("\nthe octal equivalentis :");
for(--i;i>=0;i--)
printf("%d",r[i]);
}
int dec_to_hexadec(int dec)
{
int r[10],i=0;
while(dec>0)
{
r[i]=dec%16;
i++;
dec=dec/16;
}
printf("the hexa decimal is :");
for(--i;i>=0;i--)
printf("%d",r[i]);
}
/*===================output=============*/
/*1 :convert decimal to octal
2 :convert decimal to hexadecimal
enter your choice:1
enter the decimal number :32
the octal equivalentis :40*/
/*
1 :convert decimal to octal
2 :convert decimal to hexadecimal
enter your choice:2
enter the decimal number :3
the hexa decimal is :3 */
No comments:
Post a Comment