Posted by: paolyn lazo on: September 23, 2008
My sister forced me to write a Turbo C program.
Where i the user can do the following:
a. convert a decimal to octal
b. Convert an octal to decimal
c. convert a decimal to hex
d. convert a hex to decimal
After thinking so many things. And formulating a lot of loops, trying to find out if turbo c has midstrig function that can extract each numbers.
Hehehe it seems to me that i complicate things.
This is the output program after reading books on turbo c:
#include<stdio.h>
main()
{
char choice;
int val;
printf(“Please Enter your Choice”);
printf(“(1) Decimal to Octal”);
printf(“(2) Octal to Decimal”);
printf(“(3) Decimal to Hex”);
printf(“(4) Hex to Decimal”);
choice=getche();
case (1):
printf(“Please Enter a decimal value to convert”);
scanf(“%d, &val “);
printf(“The octal value is %o”, val);
break;
case (2):
printf(“Please Enter an octal value to convert”);
scanf(“%o, &val “);
printf(“The decimal value is %d”, val);
break;
case (3):
printf(“Please Enter a decimal value to convert”);
scanf(“%d, &val “);
printf(“The hex value is %x”, val);
break;
case (4):
printf(“Please Enter a hex value to convert”);
scanf(“%x, &val “);
printf(“The octal value is %d”, val);
break;
default:
printf(“Input Error”);
}
i have learned that turbo c has a format converter for printf and scanf. So it is easy to convert to different number system.
Unlike assembly language that you have to control by bits hehehe.
November 5, 2008 at 10:39 am
..nice..!!!..