write a program which inputs an octal number and outputs its decimal equivalent. the following example illustrates the expected behaviour of the program:
input an octal number : 214
octal(214) = Decimal (532)
1
Expert's answer
2013-02-07T08:16:27-0500
#include <iostream>
void main(){ int oct0, oct, dec = 0, a = 1, r, t = 1; std::cout<<"enter an octal number: "; std::cin>>oct; oct0 = oct; while (oct0 != 0) { r = oct0%10; oct0 = oct0/10; dec += t*r; t *= 8; a++; } std::cout<<"octal("<<oct<<") = decimal("<<dec<<")\n"; system("pause"); }
Comments
Leave a comment