BASE-CONVERSION Program In C BINARY CONVERSION, OCTAL CONVERSION,HEXA-DECIMAL CONVERSION

BINARY CONVERSION, OCTAL CONVERSION,HEXA-DECIMAL CONVERSION



#include
#include
int c,r,f,i[16],j,rw,cl;
void main(void)


{
int num,a;
char ch;
void bin(int);
void hex(int);
void oct(int);
do

{
j=15; rw=0; cl=3;
for(f=0;f<=j;f++)
i[f]=0;
clrscr();

fflush(stdin);
printf("\n\n\t\t\t\t BASE-CONVERSION");
printf("\n\t\t\t\t ===============\n");
printf("\n\n\t\t 1. BINARY CONVERSION ");
printf("\n\t\t 2. OCTAL CONVERSION ");
printf("\n\t\t 3. HEXA-DECIMAL CONVERSION ");
printf("\n\t\t 4. EXIT ");
printf("\n\n\t\t\t Enter Ur choice = ");
scanf("%d",&a);
fflush(stdin);
switch(a)
{
case 1:
printf("\n\n\t\tEnter a number = ");
scanf("%d",&num);
fflush(stdin);
bin(num);
break;

case 2:
printf("\n\n\t\tEnter a number = ");
scanf("%d",&num);
fflush(stdin);
oct(num);
break;

case 3:
printf("\n\n\t\tEnter a number = ");
scanf("%d",&num);
fflush(stdin);
hex(num);
break;

case 4:
clrscr();
exit(0);
}

printf("\n\n\n\n\n\t do U want to continue...(y/n) = ");
fflush(stdin);
ch=getch();
fflush(stdin);
}
while(ch=='y'||ch=='Y');
clrscr();
}
void bin(int no)
{
c=no/2;
r=no%2;
i[j--]=r;
if(c<2)
{
i[j--]=c;
printf("\n\n\t\t\t Ans = ");
for(f=0;f<=15;f++)
{
printf("%d",i[f]);
if(rw==cl)
{
printf(" ");
cl=cl+4;
}
rw++;
}
}
else
bin(c);
}
void oct(int no)
{
c=no/8;
r=no%8;

i[j--]=r;
if(c<8)
{
i[j--]=c;
printf("\n\n\t\t\t Ans = ");

for(f=0;f<=15;f++)

{

printf("%d",i[f]);

if(rw==cl)

{
printf(" ");
cl=cl+4;
} rw++; } } else oct(c); } void hex(int no) { c=no/16; r=no%16; i[j--]=r; if(c<16) ans = "); for(f=0;f<=15;f++) { if(i[f]==10) printf(" rw="="cl)" cl="cl+4;">

No comments:

Post a Comment