recursive function for average in c

Solutions on MaxInterview for recursive function for average in c by the best coders in the world

showing results for - "recursive function for average in c"
Caterina
21 Jun 2019
1#include<stdio.h>
2 
3// Function Definition of findMean function
4float findMean(int A[], int N)
5{
6    if (N == 1)
7        return (float)A[N-1];
8    else
9        return ((float)(findMean(A, N-1)*(N-1) +
10                                    A[N-1]) / N);
11}
12 
13// Main Calling Function
14int main()
15{
16    float Mean = 0;
17    int A[] = {1, 2, 3, 4, 5};
18    int N = sizeof(A)/sizeof(A[0]);
19    printf("%.2f\n", findMean(A, N));
20    return 0;
21}