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

18 lines
473 B
C++

#include <iostream.h>
void main()
{
long num, decimal_num, remainder, base = 1, octal = 0;
cout<<"Enter a decimal integer \n";
cin>>amp num;
decimal_num = num;
while (num > 0)
{
remainder = num % 8;
octal = octal + remainder * base;
num = num / 8;
base = base * 10;
}
cout<<"Input number is ="<<decimal_num<<"\n";
cout<<"Its octal equivalent is ="<<Octal<<"\n";
}