Write a program which will print the binary equivalent for a number between 0 an
ID: 3796910 • Letter: W
Question
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;
}
Related 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.