Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello guys I am suppose to write a code to convert unasigned decimal to binary a

ID: 3741794 • Letter: H

Question

Hello guys

I am suppose to write a code to convert unasigned decimal to binary and suppose to follow this alogorithm

·       Quotient=N

·       i=0

·       di=quotient=quotient % 22

·       quotient=quotient / 2

·       While quotient0

o   i=i+1

o   di=quotient % 22

o   quotient=quotient / 2

This is what i have so far

#include <stdio.h>

int main(void)
{
int quotient,i,j, bin[64];

printf(" Please enter decimal number: ");
scanf("%d",&quotient);

i=0;
while(quotient!=0)
  

{
bin[i]=quotient%2;
quotient=quotient/2;
i=i+1;
}

printf(" The Binary value is: ");
for(j=(i-1); j>=0;j--)
printf("%d",bin[j]);

return 0;
}

It compiles, but fails the 4 test cases assigned by the proffesor. What is wrong?

Explanation / Answer

#include int main(void) { int quotient, i, j, bin[16] = {0}; printf(" Please enter decimal number: "); scanf("%d", "ient); i = 0; if(quotient == 0) { bin[i++] = 0; } while (quotient != 0) { bin[i] = quotient % 2; quotient = quotient / 2; i = i + 1; } printf(" The Binary value is: "); for (j = 15; j >= 0; j--) printf("%d", bin[j]); return 0; } 1) Your code does not convert properly if user enters 0. (I've fixed that!) 2) It is properly converting all other numbers. 3) If there are any failed test cases, please provide expected outputs for the failing test case. It is impossible to fix failing testcases with out knowing expected output.
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote