I was wondering whether there is any way to calculate variance without storing the values in an array or something. I was able to do it for mean and was able to approximately calculate variance also but was not very accurate. here is the code i used:
#include <stdio.h>
#include <math.h>
int main()
{
int n, temp;
float sum = 0, crm = 0, var = 0;
printf("Enter number of elements : ");
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
printf("Enter number %d :", i + 1);
scanf("%d", &temp);
sum = sum + temp;
crm = sum / ((float)i + 1);
var = (var*i + (temp - crm) * (temp - crm) )/ ((float)i + 1);
}
printf("\naverage : %f,appprox variance : %f\n", sum / (float)n, var);
}