Answer to Question #23786 in C++ for EMMANUEL

Question #23786
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");
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS