Write down a C program that converts decimal number to binary number and display
ID: 3679716 • Letter: W
Question
Write down a C program that converts decimal number to binary number and displays the reverse of the result e.g., binary number of 10 is 1010; your program should produce/display as 0101. Your program should ask user for a decimal number to be input and then it will display the reverse of the binary number for the input value.
Explanation / Answer
#include using namespace std; #include "stack.h" int main() { int decimal, remainder, choice; stack s; cout > decimal; cout > choice; switch (choice) { case 0: while (decimal > 0) { remainder = decimal % 2; decimal /= 2; s.push(remainder); } break; case 1: while (decimal > 0) { remainder = decimal % 8; decimal /= 8; s.push(remainder); } break; case 2: while (decimal > 0) { remainder = decimal % 16; decimal /= 16; if (remainder > 9) coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.