Answers for "function for calculate the average and standard deviation of table"

C
0

function for calculate the average and standard deviation of table

#include <stdio.h>
#include <math.h>
void The_Average(float *tab, int *length){
	float sum=0,sum2=0;
	for(int i=0;i<*length;i++){
		sum+=tab[i];
	}
	sum /=  *length;
	printf("The average of the table is : %.2f",sum);
	float tab2[*length],tab3[*length];
	for(int i=0;i<*length;i++){
		tab2[i]=tab[i]-sum;
		tab3[i]=pow(tab2[i],2);
		sum2+=tab3[i];
	}
	float result= sqrt(sum2 / (*length-1));
	printf("\nthe standard deviation is : %.2f",result);
}
int main(void) {
  int length ;
	float array[100];
	printf("enter the length of your table :");
	scanf("%d",&length);
	for(int i=0;i<length;i++){
		printf("enter the %d number :",i+1);
		scanf("%f",&array[i]);
	}
	The_Average(array,&length);
  return 0;
}
Posted by: Guest on April-22-2022

Code answers related to "function for calculate the average and standard deviation of table"

Code answers related to "C"

Browse Popular Code Answers by Language