Using float for division in C language

Anonymous user -  
[Dal] Posted messages 6205 Registration date   Status Contributeur Last intervention   -
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 réponses

Aquaran88 Posted messages 160 Status Membre 49
 
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
Anonymous user
 
Hello, thank you, but the program still displays 1.000000 instead of giving me the decimal value of 23 / 15.
0