1 #include 2 #include 3 #include 4 #include 5 int main() 6 { 7 int i; 8 int a[10
ID: 3605257 • Letter: 1
Question
1 #include
2 #include
3 #include
4 #include
5 int main()
6 {
7 int i;
8 int a[10000];
9 float sum=0;
10 float avg;
11 float var=0;
12 float sd;
13 srand(time(NULL));
14 for (i=0;i<10000;i++)
15 a[i] = rand()%6+1;
16 for (i=0;i<10000;i++)
17 sum += a[i];
18 avg = sum / i;
19 var = pow(sum-avg,2)i-1;
20 sd = sqrt(var);
21 printf("The Average of 10000 randomly generated numbers is %.4f ",avg);
22 printf("The Standard Deviation is %.4f ", sd);
23 return 0;
2. Throw a die 10,000 times and compute the average and the standard deviation. Hint: #include #include #include #include math.h> int main() int i,a[100001; float sum=0, avg, std; srand time (NULL)); for (1-0 ; iExplanation / Answer
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
#include <math.h>
int main()
{
int i;
int a[10000];
float sum=0;
float avg;
float var=0;
float sd;
srand(time(NULL));
for (i=0;i<10000;i++)
a[i] = rand()%6+1;
for (i=0;i<10000;i++)
sum += a[i];
avg = sum / i;
for(i=0; i<10; ++i)
sd += pow(a[i]-avg, 2);
sd = sqrt(sd/10);
printf("The Average of 10000 randomly generated numbers is %.4f ",avg);
printf("The Standard Deviation is %.4f ", sd);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.