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

Program 10

The document presents a C program that calculates the sum, mean, variance, and standard deviation of an array of real numbers using pointers. It prompts the user to enter the number of elements and the elements themselves, then performs the necessary calculations. The results are printed to the console.

Uploaded by

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

Program 10

The document presents a C program that calculates the sum, mean, variance, and standard deviation of an array of real numbers using pointers. It prompts the user to enter the number of elements and the elements themselves, then performs the necessary calculations. The results are printed to the console.

Uploaded by

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

# Program 11: Develop a program using pointers to compute the sum, mean and

standard deviation of all elements stored in an array of N real numbers.

#include<stdio.h>
#include<math.h>

int main()
{
float a[20], sum1 = 0, sum2 = 0, mean, var, dev;
int i, n;
printf ("Enter number of elements:");
scanf ("%d", &n);
printf ("Enter array elements:");
for (i = 0; i < n; i++)
{
scanf ("%f", a + i); // pointer arithmetic
sum1 = sum1 + * (a + i);
}
mean = sum1 / n;

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


{
sum2 = sum2 + pow ((*(a + i) - mean), 2);
}
var = sum2 / n;
dev = sqrt (var);
printf ("Sum :%f\n", sum1);
printf ("Mean :%f\n", mean);
printf ("Variance :%f\n", var);
printf ("Deviation :%f\n", dev);

return 0;
}

You might also like