Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define N 10
  5. float smoother(float inputTemp);
  6.  
  7. int main()
  8. {
  9.     float result;
  10.  
  11.     result = smoother(3);
  12.     printf("%f\n", result);
  13.    
  14.     result = 0;
  15.     result = smoother(2);
  16.     printf("%f\n", result);
  17.    
  18.     result = smoother(2);
  19.     result = smoother(2);
  20.     result = smoother(2);
  21.     result = smoother(2);
  22.     result = smoother(2);
  23.     result = smoother(2);
  24.     result = smoother(2);
  25.     result = smoother(2);
  26.     result = smoother(2);
  27.     result = smoother(2);
  28.     result = smoother(2);
  29.     result = smoother(2);
  30.     result = smoother(2);
  31.     result = smoother(2);
  32.     result = smoother(2);
  33.     result = 0;
  34.     result = smoother(8);
  35.     printf("%f\n", result);
  36.    
  37.     return 0;
  38. }
  39.  
  40. float smoother(float inputTemp) {
  41.    
  42.     int i;
  43.     static float input[N];
  44.     float sum = 0;
  45.     float avg = 0;
  46.  
  47.     for (i=8; i>=0; i--){
  48.         input[i+1] = input[i];
  49.     }
  50.     input[0] = inputTemp;
  51.      
  52.     for (i=0; i<10; i++){
  53.         sum = sum + input[i];
  54.     }
  55.  
  56.     avg = sum / N;
  57.    
  58.     return(avg);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement