| | |
Decimal system to Binary, Octal and Hexadecimal system Conversion..
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
C Syntax (Toggle Plain Text)
#include <stdio.h> main() { int ctr, bin, quotient, deci=0, binary,octal,hexa; float rem; char mark_magic; clrscr(); do { clrscr(); quotient = 1; binary = 1; gotoxy(32,3); printf("-=< MAIN MENU >=-"); gotoxy(15,5); printf("from any Number System to Decimal System conversion"); gotoxy(5,6); printf("------------------------------------------------------------------------"); gotoxy(5,7); printf("------------------------------------------------------------------------"); gotoxy(26,9); printf("[A] Binary System"); gotoxy(26,11); printf("[B] Octal System"); gotoxy(26,13); printf("[C] Hexadecimal System"); gotoxy(26,15); printf("[X] Exit"); gotoxy(26,21); printf("what's your choice?: "); mark_magic = getche(); clrscr(); switch(toupper(mark_magic)) { case 'A': clrscr(); gotoxy(10,5); printf("########^_^ Convert Decimal system to Binary system ^_^########"); gotoxy(5,6); printf("------------------------------------------------------------------------"); gotoxy(5,7); printf("------------------------------------------------------------------------"); binary = 2; gotoxy(28,9);printf("enter decimal number: "); scanf("%d",&deci); quotient = deci / binary; for(bin=1;bin>=15;bin++) { bin = deeci%2; gotoxy(28,11);printf("Equivalent in Binary is %.0f",bin); } gotoxy(51,24); printf("press any key to exit: "); getche(); clrscr(); break; case 'B': clrscr(); gotoxy(10,5); printf("########^_^ Convert Decimal system to Octal system ^_^########"); gotoxy(5,6); printf("------------------------------------------------------------------------"); gotoxy(5,7); printf("------------------------------------------------------------------------"); octal = 8; gotoxy(28,9);printf("enter decimal number: "); scanf("%d",&deci); for (ctr = 1; ctr<=deci; ctr++) quotient = deci / octal; gotoxy(28,11);printf("Equivalent in Octal is %d",quotient); gotoxy(51,24); printf("press any key to exit: "); getche(); break; case 'C': clrscr(); gotoxy(10,5); printf("########^_^ Convert Decimal system to Hexadecimal system ^_^########"); gotoxy(5,6); printf("------------------------------------------------------------------------"); gotoxy(5,7); printf("------------------------------------------------------------------------"); hexa = 16; gotoxy(28,9);printf("enter decimal number: "); scanf("%d",&deci); for (ctr = 1; ctr<=deci; ctr++) quotient = deci / hexa; gotoxy(28,11);printf("Equivalent in Hexadecimal is %d",quotient); gotoxy(51,24); printf("press any key to exit: "); getche(); break; } } while(toupper(mark_magic) != 'X'); }
this was rejected by my teacher,she said a lot of codes is missing. the problem is, I don't know what i'm going to write coz im new with C. Can you pls. help me with my problem?
thanks a lot!
Last edited by ~s.o.s~; Jul 19th, 2008 at 2:55 am. Reason: Added code tags, learn to use them.
•
•
Join Date: Jun 2008
Posts: 79
Reputation:
Solved Threads: 7
When you run a program and the first choice shows nothing, it's safe to say it's lacking! 
I re-worked Choice A, but the answer is being written out in reverse. You need to take the digits and first put them into a small array or LIFO buffer of some kind, and print them out from that array or buffer in last in, first out, ourder, so when the number is 3, the zero's are all printed out before the 1's.
Always highlight your code you want to post on the forum, and press the # sign, so it will be made to look more like code, and not regular forum text.

I re-worked Choice A, but the answer is being written out in reverse. You need to take the digits and first put them into a small array or LIFO buffer of some kind, and print them out from that array or buffer in last in, first out, ourder, so when the number is 3, the zero's are all printed out before the 1's.
Always highlight your code you want to post on the forum, and press the # sign, so it will be made to look more like code, and not regular forum text.
C Syntax (Toggle Plain Text)
#include <stdio.h> int main() { int ctr, bin, quotient, deci=0, binary,octal,hexa, gar; float rem; char mark_magic; do { clrscr(); quotient = 1; binary = 1; gotoxy(32,3); printf("-=< MAIN MENU >=-"); gotoxy(15,5); printf("from any Number System to Decimal System conversion"); gotoxy(5,6); printf("------------------------------------------------------------------------"); gotoxy(5,7); printf("------------------------------------------------------------------------"); gotoxy(26,9); printf("[A] Binary System"); gotoxy(26,11); printf("[B] Octal System"); gotoxy(26,13); printf("[C] Hexadecimal System"); gotoxy(26,15); printf("[X] Exit"); gotoxy(26,21); printf("what's your choice?: "); mark_magic = getche(); clrscr(); switch(toupper(mark_magic)) { case 'A': clrscr(); gotoxy(10,5); printf("########^_^ Convert Decimal system to Binary system ^_^########"); gotoxy(5,6); printf("------------------------------------------------------------------------"); gotoxy(5,7); printf("------------------------------------------------------------------------"); binary = 2; gotoxy(28,9);printf("enter decimal number: "); scanf("%d",&deci); quotient = deci / binary; gotoxy(28,11);printf("Equivalent in Binary is "); for(bin=1; bin <=16; bin++) { printf("%d",deci % 2); deci = deci / 2; } gotoxy(51,24); printf("press any key to exit: "); getche(); clrscr(); break; case 'B': clrscr(); gotoxy(10,5); printf("########^_^ Convert Decimal system to Octal system ^_^########"); gotoxy(5,6); printf("------------------------------------------------------------------------"); gotoxy(5,7); printf("------------------------------------------------------------------------"); octal = 8; gotoxy(28,9);printf("enter decimal number: "); scanf("%d",&deci); for (ctr = 1; ctr<=deci; ctr++) quotient = deci / octal; gotoxy(28,11);printf("Equivalent in Octal is %d",quotient); gotoxy(51,24); printf("press any key to exit: "); getche(); break; case 'C': clrscr(); gotoxy(10,5); printf("########^_^ Convert Decimal system to Hexadecimal system ^_^########"); gotoxy(5,6); printf("------------------------------------------------------------------------"); gotoxy(5,7); printf("------------------------------------------------------------------------"); hexa = 16; gotoxy(28,9);printf("enter decimal number: "); scanf("%d",&deci); for (ctr = 1; ctr<=deci; ctr++) quotient = deci / hexa; gotoxy(28,11);printf("Equivalent in Hexadecimal is %d",quotient); gotoxy(51,24); printf("press any key to exit: "); getche(); break; } }while(toupper(mark_magic) != 'X'); gar = getchar(); gar++; return 0; } /*this was rejected by my teacher,she said a lot of codes is missing. the problem is, I don't know what i'm going to write coz im new with C. Can you pls. help me with my problem? thanks a lot! */
•
•
•
•
When you run a program and the first choice shows nothing, it's safe to say it's lacking!
I re-worked Choice A, but the answer is being written out in reverse. You need to take the digits and first put them into a small array or LIFO buffer of some kind, and print them out from that array or buffer in last in, first out, ourder, so when the number is 3, the zero's are all printed out before the 1's.
Always highlight your code you want to post on the forum, and press the # sign, so it will be made to look more like code, and not regular forum text.
C Syntax (Toggle Plain Text)
#include <stdio.h> int main() { int ctr, bin, quotient, deci=0, binary,octal,hexa, gar; float rem; char mark_magic; do { clrscr(); quotient = 1; binary = 1; gotoxy(32,3); printf("-=< MAIN MENU >=-"); gotoxy(15,5); printf("from any Number System to Decimal System conversion"); gotoxy(5,6); printf("------------------------------------------------------------------------"); gotoxy(5,7); printf("------------------------------------------------------------------------"); gotoxy(26,9); printf("[A] Binary System"); gotoxy(26,11); printf("[B] Octal System"); gotoxy(26,13); printf("[C] Hexadecimal System"); gotoxy(26,15); printf("[X] Exit"); gotoxy(26,21); printf("what's your choice?: "); mark_magic = getche(); clrscr(); switch(toupper(mark_magic)) { case 'A': clrscr(); gotoxy(10,5); printf("########^_^ Convert Decimal system to Binary system ^_^########"); gotoxy(5,6); printf("------------------------------------------------------------------------"); gotoxy(5,7); printf("------------------------------------------------------------------------"); binary = 2; gotoxy(28,9);printf("enter decimal number: "); scanf("%d",&deci); quotient = deci / binary; gotoxy(28,11);printf("Equivalent in Binary is "); for(bin=1; bin <=16; bin++) { printf("%d",deci % 2); deci = deci / 2; } gotoxy(51,24); printf("press any key to exit: "); getche(); clrscr(); break; case 'B': clrscr(); gotoxy(10,5); printf("########^_^ Convert Decimal system to Octal system ^_^########"); gotoxy(5,6); printf("------------------------------------------------------------------------"); gotoxy(5,7); printf("------------------------------------------------------------------------"); octal = 8; gotoxy(28,9);printf("enter decimal number: "); scanf("%d",&deci); for (ctr = 1; ctr<=deci; ctr++) quotient = deci / octal; gotoxy(28,11);printf("Equivalent in Octal is %d",quotient); gotoxy(51,24); printf("press any key to exit: "); getche(); break; case 'C': clrscr(); gotoxy(10,5); printf("########^_^ Convert Decimal system to Hexadecimal system ^_^########"); gotoxy(5,6); printf("------------------------------------------------------------------------"); gotoxy(5,7); printf("------------------------------------------------------------------------"); hexa = 16; gotoxy(28,9);printf("enter decimal number: "); scanf("%d",&deci); for (ctr = 1; ctr<=deci; ctr++) quotient = deci / hexa; gotoxy(28,11);printf("Equivalent in Hexadecimal is %d",quotient); gotoxy(51,24); printf("press any key to exit: "); getche(); break; } }while(toupper(mark_magic) != 'X'); gar = getchar(); gar++; return 0; } /*this was rejected by my teacher,she said a lot of codes is missing. the problem is, I don't know what i'm going to write coz im new with C. Can you pls. help me with my problem? thanks a lot! */
![]() |
Similar Threads
- number system conversion (C++)
Other Threads in the C Forum
- Previous Thread: Trafic signal control program code needed
- Next Thread: base coversion
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue number oddnumber odf opensource overwrite owf pdf performance pointer posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket socketprograming spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi






