programming-examples/c++/Basic/Decimal to Octal.cpp

18 lines
473 B
C++
Raw Normal View History

2019-11-18 14:44:36 +01:00
#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";
}