Menu

[Solved]1 Following Algorithm Convert Decimal Number Int Binary Number Ex Convert 13 1101 First Di Q37254434

1.) The following is the algorithm to convert a decimal number (int) to a binary number Ex: Convert 13 to 1101 a) First dividHowever, the output statement is after a recursive function call within If the number is greater than zero, the function is r1.) The following is the algorithm to convert a decimal number (int) to a binary number Ex: Convert 13 to 1101 a) First divide the integer number by 2, (binary is base 2). Ex: int num 5; int base 2; 5 2 2 with a remainder of 1 b) Write down the remainder c) Then divide the new number by two and write down the number Each time the new number is the quotient from the previous expression. – -2 = 1 with a remainder of 0 2 Write the remainders moving from right to left. d) Repeat steps a and b until the new number (quotient) is o 1-0 with a remainder of 1 2 Answer 1 01 2.) Write a program that converts integer values to binary. 3.) Your program should first prompt the user to enter a non-negative integer. 4.) The program should have a recursive function named: dec ToBinary. The int values should be O or greater. – With the first function call in main0, an integer value, initially representing the value – The function is void-returning. – The function divides the number that is passed as an argument by2 – The remainder is output to the screen. entered by the user is passed to the function. However, the output statement is after a recursive function call within If the number is greater than zero, the function is recursively called, with the The base case for the function is when the number equals zero, at which time, the function body. quotient of the previous division being passed as an argument zero is output to the screen, and recursive function calls stop. – – 5.) Compile and run the program. 6.) Turn in your source code and output demonstrating the function works successfully. * OUTPUT: Enter a non-negative integer value: 0 Decimal o 0 binary Press any key to continue..*/ OUTPUT: Enter a non-negative integer value: 37 Decimal 37 0100101 binary. Press any key to continue.* OUTPUT Enter a non-negative integer value:1 Decimal -1 = Invalid entry binary. Press any key to continue./ Show transcribed image text 1.) The following is the algorithm to convert a decimal number (int) to a binary number Ex: Convert 13 to 1101 a) First divide the integer number by 2, (binary is base 2). Ex: int num 5; int base 2; 5 2 2 with a remainder of 1 b) Write down the remainder c) Then divide the new number by two and write down the number Each time the new number is the quotient from the previous expression. – -2 = 1 with a remainder of 0 2 Write the remainders moving from right to left. d) Repeat steps a and b until the new number (quotient) is o 1-0 with a remainder of 1 2 Answer 1 01 2.) Write a program that converts integer values to binary. 3.) Your program should first prompt the user to enter a non-negative integer. 4.) The program should have a recursive function named: dec ToBinary. The int values should be O or greater. – With the first function call in main0, an integer value, initially representing the value – The function is void-returning. – The function divides the number that is passed as an argument by2 – The remainder is output to the screen. entered by the user is passed to the function.
However, the output statement is after a recursive function call within If the number is greater than zero, the function is recursively called, with the The base case for the function is when the number equals zero, at which time, the function body. quotient of the previous division being passed as an argument zero is output to the screen, and recursive function calls stop. – – 5.) Compile and run the program. 6.) Turn in your source code and output demonstrating the function works successfully. * OUTPUT: Enter a non-negative integer value: 0 Decimal o 0 binary Press any key to continue..*/ OUTPUT: Enter a non-negative integer value: 37 Decimal 37 0100101 binary. Press any key to continue.* OUTPUT Enter a non-negative integer value:1 Decimal -1 = Invalid entry binary. Press any key to continue./

Expert Answer


Answer to 1.) The following is the algorithm to convert a decimal number (int) to a binary number Ex: Convert 13 to 1101 a) First … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *