Write a program which will print the binary equivalent for a


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.

Solution

#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;

}

 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 repr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site