why is that when I print a result from my function, it prints out 0? I tried using a prototype, and followed an example from my teacher, but no dice. Pretty lost here.
#define _CRT_SECURE_NO_WARNINGS #include <stdlib.h> #include <stdio.h> #include <math.h> double energie_cinetique(double m, double v) { double resultat; resultat = 1 / 2 * m * (v * v); return resultat; } int main(void) { double reponse; reponse = energie_cinetique(10, 5); printf("Energie pour m=10 kg et v=5 m/s: %d", reponse); system("pause"); return EXIT_SUCCESS; }
%lfinstead of%din yourprintf()statement. Also it maybe a good idea to use1.0/2.0 * m * (v * v)to ensure floating point arithmetic. Or else1/2integer division is0and1.0/2=0.5or1/2.0=0.5or1.0/2.0=0.5