Friday 15 April 2011

algorithm - C programming error float -



algorithm - C programming error float -

this question has reply here:

c: converting farenheit celsius 3 answers

this code. s (arithmetic mean) done right, have valid result. other calculations i'm getting error: floating point exception (core dumped).

does know wrong code?

#include <stdio.h> #include <math.h> main () { int a,b,c; double s,h,g,k; printf ("unesite 3 cela broja\n"); scanf ("%d%d%d", &a, &b, &c); s=(a+b+c)/3; printf ("aritmeticka s.v. je: %.2lf\n", s); /* should formula medium value of harmonic number */ h=3/((1/a)+(1/b)+(1/c)); printf ("harmonijska s.v. je: %.2lf\n", h); /* should http://upload.wikimedia.org/math/a/f/f/aff7a590d055d563ceea52fd66fe7ee2.png */ k=sqrt ((pow(a,2)+pow(b,2)+pow(c,2))/3); printf ("kvadratna s.v. je: %.2lf\n", k); /* , http://upload.wikimedia.org/math/e/3/4/e348daea2f4f2bb60f5cb40706fcbad4.png */ g=pow(a*b*c,1/3); printf ("geometrijska s.v. je: %.2lf\n", g); homecoming 0; }

almost divisions integer divisions. , if split integer larger value result truncated zero. partition 0 not good, , abort program.

change divisions floating point divisions.

c algorithm

No comments:

Post a Comment