C++ Program to Convert Octal to Decimal
Write C++ Program to Convert Octal to Decimal
// CPP Program to convert Octal to Decimal
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n, ans = 0;
cout << "Enter the Octal Number :--> ";
cin >> n;
int i = 0;
while(n != 0)
{
int digit = n % 10;
ans = ans + (digit* pow(8, i));
n = n / 10;
i++;
}
cout << "The Decimal Number is :--> " << ans;
return 0;
}
Output:
Enter the Octal Number :--> 456
The Decimal Number is :--> 302