Problem:
To convert the given decimal no into binary or octal or hexadeciaml with menu option , if user enter the base 8 it should be converted into octal
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,intex[]={0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F'},data[100],i=0,j,base;
clrscr();
printf("\n enter the no ..");
scanf("%d",&a);
printf("\n enter the base \nBinary--->2\nOctal--->8\nHexadecimal--->16");
scanf("%d",&base);
while(a!=0)
{
data[i]=a%base;
i++;
a=a/base;
}
for(i--;i>=0;i--)
{
j=data[i];
if(j<=9)
printf("%d",intex[j]);
else
printf("%c",intex[j]);
}
getch();
}
Output:
To convert the given decimal no into binary or octal or hexadeciaml with menu option , if user enter the base 8 it should be converted into octal
Solution:
#include<conio.h>
void main()
{
int a,b,intex[]={0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F'},data[100],i=0,j,base;
clrscr();
printf("\n enter the no ..");
scanf("%d",&a);
printf("\n enter the base \nBinary--->2\nOctal--->8\nHexadecimal--->16");
scanf("%d",&base);
while(a!=0)
{
data[i]=a%base;
i++;
a=a/base;
}
for(i--;i>=0;i--)
{
j=data[i];
if(j<=9)
printf("%d",intex[j]);
else
printf("%c",intex[j]);
}
getch();
}
Output:
No comments:
Post a Comment