0% found this document useful (0 votes)
23 views1 page

BCSL 044 Assesment

The document describes a C program to read data from a file, calculate the mean, variance, and standard deviation of the data. The program inputs data from a file, calculates the sum and average of the data, then uses the average to calculate the variance and standard deviation before outputting the results.

Uploaded by

sam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views1 page

BCSL 044 Assesment

The document describes a C program to read data from a file, calculate the mean, variance, and standard deviation of the data. The program inputs data from a file, calculates the sum and average of the data, then uses the average to calculate the variance and standard deviation before outputting the results.

Uploaded by

sam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Develop a program in C to construct a frequency distribution and hence calculate mean &

standard deviation for the data mentioned in problem 1. Your program should make
provision to input data from a file and output results on the screen (you may also use
Struges’ rule).   

#include <stdio.h>
#include <math.h>
#define datasize 100

int main()
{
float x[datasize];
int i, n;
float average, variance, std_deviation, sum = 0, sum1 = 0;

FILE *myFile;

myFile = fopen("C:\\Users\\Dell\\Desktop", "r");

for (i = 0; i < 100; i++)


{
fscanf(myFile, "%f", &x[i]);
}

/* Compute the sum of all elements */


for (i = 0; i < n; i++)
{
sum = sum + x[i];
}
average = sum / (float)n;
/* Compute variance and standard deviation */
for (i = 0; i < n; i++)
{
sum1 = sum1 + pow((x[i] - average), 2);
}
variance = sum1 / (float)n;
std_deviation = sqrt(variance);
printf("Average of all elements = %.2f\n", average);
printf("variance of all elements = %.2f\n", variance);
printf("Standard deviation = %.2f\n", std_deviation);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy