-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain12.c
75 lines (64 loc) · 1.6 KB
/
main12.c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int random_int(int min, int max)
{
return min + rand() % (max+1 - min);
}
int main() {
int array[100];
int i,sum=0;
int choice;
int N;
printf("How to create the array.\n");
printf("Random numbers. :1\n");
printf("To be entered manually. :2\n");
printf("Please make your choice: ");
scanf("%d",&choice);
printf("Enter the number of elements:");
scanf("%d",&N);
if (choice == 2){
for(i=0;i<N;i++)
{
scanf("%d",&array[i]);
sum += array[i];
}
float mean=(float)sum/N;
printf("Mean:%.2f\n",mean);
int t=0;
for(i=0;i<N;i++) {
t+=pow(array[i]-mean,2);
}
float standard_dev=sqrt((float)t/(N-1));
printf("Standard Deviation: %f\n",standard_dev);
}
else if (choice == 1)
{
int max_number,minimum_number = 0;
printf("Min and Max: ");
scanf("%d",& minimum_number);
scanf("%d",& max_number);
int array[100];
for (int i=0;i<N;i++)
{
array[i]= random_int(minimum_number,max_number);
sum += array[i];
}
for(int i=0;i<N;i++)
{
printf("%d ",array[i]);
}
float mean=(float)sum/N;
printf("Mean: %.2f\n",mean);
int t=0;
for(i=0;i<N;i++) {
t+=pow(array[i]-mean,2);
}
float standard_dev=sqrt((float)t/(N-1));
printf("Standard Deviation: %f\n",standard_dev);
}
else {
printf("You must choose one of the two options.!");
}
return 0;
}