Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

why 0+0 is not 0 and why is it 00 ?

jarvis38jarvis38 Member Posts: 3

include <stdio.h>

include <curses.h>

int main()
{
int integral, binaryInt = 0, i = 1;
float binaryFract = 0, k =0.1f, fractional, temp1, binaryTotal, f;

printf("***** Convert float to binary *******\n");
printf("\nEnter float value : ");
scanf("%f",&f);

//Separating the integral value from the floating point variable
integral = (int)f;

//Separating the fractional value from the variable
fractional = f - (int)f;

//Loop for converting decimal to binary
while(integral>0)
{
    binaryInt = binaryInt + integral % 2 * i;
    i = i * 10;
    integral = integral / 2;
}
printf("%d",binaryInt);
return 0;

}

in the above code , why does "while loop" give an output of 00 instead of 0 when adding 0+0?

Comments

Sign In or Register to comment.