lucproblem014-short.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 12 Dec 2025
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
Write a function that receives integers and returns the sum, average and standard deviation of these numbers. Call this function from main() and print the result in main()
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
#include <math.h>
void stats(double *, double *, double *);
int main()
{
double sum, average, standardDeviation;
stats(&sum, &average, &standardDeviation);
printf("\n--- Stats ---"
"\nSum: %g"
"\nAverage: %g"
"\nStandard Deviation: %g",
sum, average, standardDeviation);
return 0;
}
void stats(double *sum, double *average, double *standardDeviation)
{
int n;
printf("How many numbers you want to give input: ");
scanf("%d", &n);
double inputNumber[n];
int i;
printf("\n--- Enter Numbers ---\n");
for (i = 0; i < n; i++)
{
printf("Enter number %d: ", i + 1);
scanf("%lf", &inputNumber[i]);
}
double tempSum = 0;
for (i = 0; i < n; i++)
tempSum += inputNumber[i];
double tempAverage = tempSum / n;
double tempStandardDeviation = 0.0;
if (n > 1)
{
double tempSumation = 0;
for (i = 0; i < n; i++)
tempSumation += pow((inputNumber[i] - tempAverage), 2.0);
tempStandardDeviation = sqrt(tempSumation / (n - 1));
}
*sum = tempSum;
*average = tempAverage;
*standardDeviation = tempStandardDeviation;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55