QUESTION DESCRIPTION :
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.
TEST CASE 1
TEST CASE 2
Decimal value:29
Octal value:35
Hexadecimal value:1d
Selvan from SRM Public school is studying 3r
grade in school, her maths mam gave her a problem to convert the decimal
number in octal and hexadecimal . Since her mam gave so much problems
to solves.She went to his brother who is computer programmer and
requested to create a program that converts automatically given integer
to decimal, octal and hexadecimal equivalent. Let us help an programmer
to do program?
Refer sample input and output for formatting specification.
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.
INPUT
25
OUTPUT
Decimal value:25
Octal value:31
Hexadecimal value:19
Octal value:31
Hexadecimal value:19
TEST CASE 2
INPUT
29
OUTPUT
Decimal value:29
Octal value:35
Hexadecimal value:1d
EXPLANATION :
The objective of this code is to accept an integer value from the user and print its octal ( decimalTOoctal ) and hexadecimal counterparts ( decimalTOhexadecimal )
The objective of this code is to accept an integer value from the user and print its octal ( decimalTOoctal ) and hexadecimal counterparts ( decimalTOhexadecimal )
ALGORITHM :
For OCTAL :
- Accept the given number as integer( a )
- If the number is less than 8, print the exact number as answer
- If the number is > 8 , take the modulus by 8 and save the remainder in an array ( octal[] )
- Do the above steps again but replace the number with the quotient , until you get a quotient less than 8.
- Print the remainders in reverse order (bottom to top)
- The result is the octal of the given decimal number.
- Accept the given number as integer( a )
- If the number is less than 10, print the exact number as answer
- If the number is > 10 and less than 16 , convert it to a character (10 is a , 11 is b ...).
- If the number is > 16 , take the modulus by 16 and save the remainder in an array ( hexad[] )
- Do the above steps again but replace the number with the quotient , until you get a quotient less than 16.
- Print the remainders in reverse order (bottom to top)
- The result is the hexadecimal of the given decimal number.
CODE |
No comments:
Post a Comment