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

Write a program which will print the binary equivalent for a number between 0 an

ID: 3796910 • Letter: W

Question


Write a program which will print the binary equivalent for a number between 0 and 255 If the input is In the proper range, print the 8 bit unsigned binary representation. If the input is out of range, print an error message Your output should be similar to: Input a value between 0 and 255: 200 The unsigned binary equivalent is: 1100 1000 Input a value between 0 and 255: 380 ERROR! Input value of 300 is out of range for this program. You can design this program using a series of if statements. We will work on the design together in lab. (We will rewrite this program using a loop in chapter 5.) Run your program enough times to produce the output for the following numbers 200, 63. 255, 1, 7, 144, -1, and 320.

Explanation / Answer

#include<stdio.h>


int main(){

int d,r,q;

int b[25],i=1,j;


printf("Input a value Between 0 and 255: ");

scanf("%d",&d);
if(d>0 && d<=255)
{
q = d;


while(q!=0){

b[i++]= q % 2;

q= q / 2;

}


printf("The Unsigned Binary Equivalent is: ");

for(j = i -1 ;j> 0;j--)

printf("%d",b[j]);

}
else{
  
printf("Error! Input a value %d is out of range for this program ",d);
}

return 0;

}

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