Created
June 21, 2018 04:29
-
-
Save aligalehban/232555a3617d966bae9f41c8e6244ee5 to your computer and use it in GitHub Desktop.
convert octal to decimal in c++ source code - www.alighalehban.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
int octalToDecimal(int octalNumber); | |
int main() | |
{ | |
int octalNumber; | |
cout << "Enter an octal number: "; | |
cin >> octalNumber; | |
cout << octalNumber << " in octal = " << octalToDecimal(octalNumber) << " in decimal"; | |
return 0; | |
} | |
// Function to convert octal number to decimal | |
int octalToDecimal(int octalNumber) | |
{ | |
int decimalNumber = 0, i = 0, rem; | |
while (octalNumber != 0) | |
{ | |
rem = octalNumber % 10; | |
octalNumber /= 10; | |
decimalNumber += rem * pow(8, i); | |
++i; | |
} | |
return decimalNumber; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment