programming-examples/c++/_Basic/Binary to Octal.cpp
2019-11-15 12:59:38 +01:00

17 lines
439 B
C++

#include < iostream.h>
int main()
{
long int binarynum, octalnum = 0, j = 1, remainder;
cout<<"Enter the value for binary number: ";
cin>>binarynum;
while (binarynum != 0)
{
remainder = binarynum % 10;
octalnum = octalnum + remainder * j;
j = j * 2;
binarynum = binarynum / 10;
}
cout<<"Equivalent octal value:"<<octalnum;
return 0;
}