Thread: average

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    1

    average

    please, help, why doesn't it work?
    P S srednia mean average

    Code:
    #include <math.h>
    #include <stdio.h>
    
    
    #define N 10
    
    
    
    
    double srednia(int [], int);
    
    
    int main() {
        int tablica[N] = {23, 41, 432, 543, 41, 1543, 76, 21, 54, 12};
        int wynik = 0;
        int i;
        double sr = srednia(tablica, N);
    
    
        printf("%f", sr/N);
    
    
        return 0;
    }
    
    
    double srednia(int t[], int n){
        int i;
        int wynik;
        
    
    
        for(i = 0; i < n; i++){
             wynik += t[i];
        }
    
    
        return wynik/n;
    }

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    550
    Change line 20 to:
    Code:
      printf( "%f\n", sr );
    And line 38 to:
    Code:
      return (double)wynik / n;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Average of odd and even
    By Abcdefji in forum C Programming
    Replies: 4
    Last Post: 07-25-2016, 01:21 AM
  2. Replies: 9
    Last Post: 06-25-2015, 04:10 PM
  3. Replies: 27
    Last Post: 02-14-2015, 11:17 AM
  4. Average
    By winterx in forum C++ Programming
    Replies: 3
    Last Post: 07-15-2008, 03:01 AM
  5. help with average
    By tmoney$ in forum C Programming
    Replies: 3
    Last Post: 05-09-2003, 05:46 PM

Tags for this Thread