+1 vote

float a = 1 / 2;

This means, that let's create a variable called a with the type float and set the value to be 1 / 2;

1 / 2

means let's divide the integral number 1 by the integral number 2. This is an integral division (resulting in an integral number) so the result is 0.

Then this zero is set to be the value of a, which involves an int to float conversion (casting).

What you want here is a float division, to begin with. You can tell your compiler that you are using floating point literals, not integral literals by the f suffix:

float a = 1.0f / 2.0f;

If you do not add the f suffix the code will still do what you'd expect it to do, but it will do a double division as floating point literals without the f suffix default to double type, not float.

I hope this makes more sense now.

+1 vote

#include<stdio.h>

int main() {

float a,b,c;

printf("enter the two no : ");

scanf("%f %f",&a,&b);

c=a/b;

printf("%f",c);

return 0;

}

int main() {

float a,b,c;

printf("enter the two no : ");

scanf("%f %f",&a,&b);

c=a/b;

printf("%f",c);

return 0;

}

...