Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

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("
the 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;
}
 
PREVIOUS NEXT
Tagged: #function #calculate #average #standard #deviation #table
ADD COMMENT
Topic
Name
7+8 =