int averege4( int a , int b , int c , int d ) { return ( averege3 ( a , b , c ) + d) / 2; }
int averege3( int a , int b , int c ) { return ( averege2 ( a , b ) + c) / 2; }
int averege2( int a , int b ) { return ( averege1 ( a ) + b) / 2; }
int averege1( int a ) { return ( 0 + a / 2 ); }
why do the result is wrong?
There are filter solutions where new and old samples gets different weight instead of just taking the average of the samples. But your code does not seem to produce any meaningful result.
If I have the values 10,10,10 and 10, I would expect the average to be 10. Can you honestly say that your code produces that result?
This is not a computer science problem. This is a very, very, basic math problem from junior days in school.
Just a followup - have you recently looked at recursive functions? Are you sure this is a problem that is best solved by some form of recursive-descent solution?
it works now. you must put in a program called main and call averege4 from there.
You mean a function called main().
View all questions in Keil forum