CPP program convert octal to decimal
In this program, you will learn about the conversion of octal to decimal number in the cpp programming language.
In order to understand the following code must have the knowledge of the following topics:
Code:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int octalNumber,originalnumber;
cout << "Enter an octal number "<<endl;
cin >> octalNumber;
originalnumber=octalNumber;
int decimalNumber = 0, i = 0, remainder;
while (octalNumber != 0)
{
remainder = octalNumber % 10;
octalNumber /= 10;
decimalNumber += remainder * pow(8, i);
i++;
}
cout << originalnumber << " in octal = " << decimalNumber << " in decimal"<<endl;
return 0;
}
Output:
Enter an octal number
12345
12345 in octal = 5349 in decimal
Comments
Post a Comment