| | |
Octal to Decimal number conversion program
![]() |
•
•
Join Date: Feb 2008
Posts: 8
Reputation:
Solved Threads: 0
I'm trying to make a program that converts octal numbers to decimal numbers. I know the concept is taking the %10 of the number to get the first digit, /10 the number then take the %10 to get the second digit and multiplying by increase powers of 8, but I have no idea how to translate this to a program. Could someone please guide me in the right direction.
C Syntax (Toggle Plain Text)
#include <stdio.h> int main () { int num1, base8, x, y, n, lastDigit; printf("Enter an integer in base 8: "); scanf("%d", &num1); num1 %10 =lastDigit; n = 1; x=num1 if(num1 > 10){ x/10 = x; x %10 =y; while (x != y) { x/10 = x; x %10 =y; base8 = y*8^n n = n + 1; }} sum= base8+lastDigit; printf("%d", sum); return 0; }
Last edited by newport; Feb 13th, 2008 at 2:19 am.
It would help if you'd format your code so we can follow it's flow. Proper indentation is crucial to understanding.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
>I'm trying to make a program that converts octal numbers to decimal numbers.
I don't suppose this would work for you:
I don't suppose this would work for you:
c Syntax (Toggle Plain Text)
#include <stdio.h> int main ( void ) { int number; scanf ( "%o", &number ); printf ( "%d\n", number ); return 0; }
I'm here to prove you wrong.
Firstly,
base8 = y*8^n does not have semi-colon at the end of the statement. Secondly, ^ is not a power operator. I think you are confusing with Visual Basic. Moreover, x/10 = x; and x %10 =y; are not right. It should be x = x / 10 . Last edited by invisal; Feb 13th, 2008 at 1:23 pm.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Behind every smile is a tear.
Visal .In
![]() |
Similar Threads
- number system conversion (C++)
- Pls. help with my assignment -_- (C++)
- Help! Decimal to binary conversion (C)
- conversion (C)
Other Threads in the C Forum
- Previous Thread: please give me a simple file handling program
- Next Thread: converting char to int?
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks bash binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile creafecopyofanytypeoffileinc createprocess() database dynamic execv fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux histogram ide inches include infiniteloop initialization input interest intmain() iso keyboard km license linked linkedlist linux list looping lowest matrix meter microsoft number oddnumber open opendocumentformat openwebfoundation owf pdf pointer pointers posix power probleminc process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing scheduling segmentationfault send sequential single socket socketprogramming standard strchr string suggestions systemcall test testautomation testing threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






