Objectives
- Learn binary numbers and how to use recursive functions Develop some methods that will be useful in your future!
You can find hw8 note: binary and recursio n on Moodle.
Questions
Question 1: decimalToBinaryIterative
Write a function decimalToBinaryIterative that converts a decimal value to binary using a loop. This function takes a single parameter, a non-negative integer, and returns a string corresponding to the binary representation of the given value.
Function specifications:
- The function name: decimalToBinaryIterative
- The function parameter: An integer to be converted to binary
- Your function should return the binary representation of the given value as a string
- Your function should not print anything
- Your function should use a loop
| Sample main (Be sure to test all methods!) | Expected outputs |
| decimalToBinaryIterative(5) decimalToBinaryIterative(8) | 1011000 |
The file should be named as iterative.cpp . Dont forget to head over to the code runner on Moodle and paste your solution in the answer box! In the main, make sure to have test cases.
Question 2: decimalToBinaryRecursive
Write a function decimalToBinaryRecursive that converts a decimal value to binary using recursion. This function takes a single parameter, a non-negative integer, and returns a string corresponding to the binary representation of the given value.
Function specifications:
- The function name: decimalToBinaryRecursive
- The function parameter: An integer to be converted to binary
- Your function should return the binary representation of the given value as a string
- Your function should not print anything
- Your function should use recursion. Loops are not allowed.
| Sample main (Be sure to test all methods!) | Expected outputs |
| decimalToBinaryRecursive(5) decimalToBinaryRecursive(8) | 1011000 |
The file should be named as recursive.cpp . Dont forget to head over to the code runner on Moodle and paste your solution in the answer box! In the main, make sure to have test cases.

![[Solved] CSCI1300 Homework 8-Binary numbers and recursive functions](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] CSCI1300 Homework 5-Arrays and vectors](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.