The program is written here to convert an octal number into its equivalent decimal0 number. The octal number is taken as input then it is converted into its equivalent decimal number.
For example, if an octal number is
Now, the equivalent decimal number will be calculated by multiplying each digit of the octal number with the increasing power of 8 (the power will starts from 0 and will increase from right to left).
Therefore, the equivalent decimal number:
7× + 5×
= 56 + 5
INPUT: An octal number
OUTPUT: Equivalent decimal number
Step 1: [Taking the input]
Read n [an octal number]
Step 2: [Converting from octal to decimal]
While n>0 repeat
[Calculating the power of 8 and multiplied with the octal digit]
Set d<-d+(n mod 10)×p
[Increasing the power]
[End of ‘while’ loop]
Print the decimal number stored in ‘d’
Step 3: Stop.
//calculating the power of 8 and multiplied
//with the octal digit
//increasing the power
The time complexity of this program is O(m) where ‘m’ is the number of digits of the octal number.
The space complexity of this program is O(1) as it requires a constant number of memory spaces to execute for any given input.