Using float for division in C language

Je voudrais diviser deux int pour avoir un float. Mais dans mon programme, ça ne fonctionne pas il m'affiche 1.000000. Est-ce en raison de mon void modification(int * a ) ?
Mon programme :
1 #include <stdio.h> 2 void modification(int * a ) 3 4 { 5 *a=15; 6 } 7 int main() 8 { 9 int a = 15; 10 int b = 23; 11 float f; 12 printf("%d\n",b); 13 modification(&b); 14 f = (float)b / a; 15 printf("%f \n",f) ; 16 17 return 0; 18 19 } 20</stdio.h>

3 answers

  • Votes
  • Date
  • Descending date
  1. Hello,

    An int is a whole number, so it is impossible to divide it to obtain a float. To correct this error, you just need to convert your int variables directly into float.
    1. Hello, thank you, but the program still displays 1.000000 instead of giving me the decimal value of 23 / 15.