Programmer

Tuesday, 5 June 2018

Program to Convert Binary Number to Decimal And Octal.

#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();

}



No comments:

Post a Comment

Program To Print Particular Line From File.

#include<fstream.h> #include<conio.h> #include<stdlib.h> void main() { ifstream fin; int count=0,num,l=1; char ...