# Thread: Help with Calculating quotient using float

1. ## Help with Calculating quotient using float

1. Code:
2. #include <stdio.h>
3. int main ()
4. {
5. /* variable definition: */
6. float a, b, c;
7. /* variable initialization */
8. a = 1.1;
9. b = 1.1;
10. c = a / b;
11. printf("Integers (a,b) and quotient (c) are : %d,%d,%d \n", a,b,c);
12. return 0;
13. }
Obviously the result should be 1, but it is not working and I can't figure out why. I am very new to programming and to C so I appreciate any help. • The printf function requires an exact match between the conversion specifier and the type of the argument. Otherwise the result is undefined, which means anything can happen (which usually is garbage output like you are experiencing).

The d conversion specifier expects an integer argument, but a, b and c are floats. To get the correct results you should use the f specifier, or convert the arguments to int. Like so:

Code:
```printf("Integers (a,b) and quotient (c) are : %f,%f,%d \n", a,b, (int)c);

// or

printf("Integers (a,b) and quotient (c) are : %f,%f,%f \n", a,b, c);```
Also note that the length modifier that usually precedes the conversion specifier (for instance the l in ld, for long) also results in undefined behaviour if not correctly matched with its argument:

Code:
```int a = 10;
long b = 10;
printf("%ld", a);         // undefined behavior; specifier doesn't match
printf("%ld", b);         // correct
printf("%ld", (long)a)    // correct; argument converted to long.``` • Popular pages Recent additions 1.1;, float, quotient, variable, working 