Program in C to calculates an average of the numbers entered

Write a program in C to calculates an average of the numbers entered

#include <stdio.h>

int Average(int i);

int main()
{
            int num;
            do
            {
                        printf("Enter numbers.\n");
                        scanf("%d",&num);
                        if(num != -1)
                                    printf("The average is %d", Average(num));
                        printf("\n");
           
            } while(num>-1);

            return 0;
}

int Average(int i)
{
            static int sum = 0, count = 0;
            sum = sum + i;
            count++;
            return sum / count;
}


Post a Comment