Write a c program to Convert the decimal number to octal number Convert decimal number to hexadecimal number

#include<stdio.h>
#include<conio.h>
void main()
{
void oct(int);
void hex(int);
while(1)
{
int n,ch;
clrscr();
printf("\n enter the number \n");
scanf("%d",&n);
printf("\n 1:octal \n 2:hexadecimal \n 3:exit \n");
printf("\n enter the choice \n");
scanf("%d",&ch);
switch(ch)
{
case 1:
oct(n);
break;
case 2:
hex(n);
break;
case 3:exit(0);
}
getch();
}
}

void oct(int n)
{
int a[10],i=0;
while(n!=0)
{
a[i]=n%8;
i++;
n=n/8;
}
for(--i;i>=0;i--)
printf("%d",a[i]);
}

void hex(int n)
{
int b[10],i=0;
while(n!=0)
{
b[i]=n%16;
i++;
n=n/16;
}
for(--i;i>=0;i--)
{
if(b[i]<10)
printf("%d",b[i]);
else
{
switch(b[i])
{
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",b[i]);
 }
 }
 }
 }

Comments

  1. there is an error pointing about "call to undefined function 'exit' in function main"

    ReplyDelete
  2. PLS this doesn't work for me. there is error!!!

    ReplyDelete

Post a Comment