#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int a[20],octal[20],i,j,temp,flag=0,sum=0,o=0;
long num;
clrscr();
cout<<"Enter Number :";
cin>>num;
i=0;
while(num)
{
temp=num%10;
num=num/10;
flag++;
a[i]=temp;
i++;
}
cout<<"Binary Number is :";
for(i=0;i<flag;i++)
{
cout<<a[i];
}
for(i=0;i<flag;i++)
{
sum+=(pow(2,i)*a[i]);
}
cout<<"\n\nDecimal Number is :"<<sum;
i=0;
while(sum)
{
temp=sum%8;
sum=sum/8;
o++;
octal[i]=temp;
i++;
}
cout<<endl<<"Octal Number is :";
for(i=o-1;i>=0;i--)
{
cout<<octal[i];
}
getch();
}
#include<conio.h>
#include<math.h>
void main()
{
int a[20],octal[20],i,j,temp,flag=0,sum=0,o=0;
long num;
clrscr();
cout<<"Enter Number :";
cin>>num;
i=0;
while(num)
{
temp=num%10;
num=num/10;
flag++;
a[i]=temp;
i++;
}
cout<<"Binary Number is :";
for(i=0;i<flag;i++)
{
cout<<a[i];
}
for(i=0;i<flag;i++)
{
sum+=(pow(2,i)*a[i]);
}
cout<<"\n\nDecimal Number is :"<<sum;
i=0;
while(sum)
{
temp=sum%8;
sum=sum/8;
o++;
octal[i]=temp;
i++;
}
cout<<endl<<"Octal Number is :";
for(i=o-1;i>=0;i--)
{
cout<<octal[i];
}
getch();
}
No comments:
Post a Comment