-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESTADISTICA DE VECTOR.cpp
126 lines (109 loc) · 2.46 KB
/
ESTADISTICA DE VECTOR.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// ESTADISTICA DE VECTOR.cpp: archivo de proyecto principal.
#include "stdafx.h"
#include "iostream"
#include "Math.h"
using namespace System;
using namespace std;
void leervector(double V[20], int &n)
{
int i;
do {
cout << "Ingrese el tamano del vector (max 20): ";
cin >> n;
if (n > 20) {
cout << "El tamano ingresado excede el limite. " << endl;
cout << " =======================" << endl;
cout << " VUELVA A INTENTARLO" << endl;
cout << " ===================" << endl;
}
} while (n > 20);
for (i = 0; i < n; i++)
{
cout << "Ingrese V[" << i << "]: ";
cin >> V[i];
}
}
void mostrarvector(double V[20], int n)
{
int i;
cout << "El vector leido fue: " << endl;
for (i = 0; i < n; i++)
{
cout << "V[" << i << "]: " << V[i] << endl;
}
}
void ordenarvector(double V[20], int n)
{
double tem;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (V[j] < V[i])
{
tem = V[i];
V[i] = V[j];
V[j] = tem;
}
}
}
cout << "El vector ordenado es: " << endl;
for (int i = 0; i < n; i++)
{
cout << "V[" << i << "]: " << V[i] << endl;
}
}
void calcularmediana(double V[20], int n)
{
double mediana;
if (n % 2 == 0)
{
mediana = (V[n / 2] + V[(n / 2) - 1]) / 2;
}
else
{
mediana = V[(n - 1) / 2];
}
cout << "La mediana del vector es " << mediana << endl;
}
void calcularsumamedia(double V[20], int n, double &media)
{
double suma;
media = 0;
for (int i = 0; i < n; i++)
{
suma = suma + V[i];
}
cout << "La suma del vector es: " << suma << endl;
cout << "La media del vector es: " << suma / n << endl;
media = suma / n;
}
void calcularvarianza(double V[20], int n, double media,double &varianza)
{
varianza = 0;
for (int i = 0; i < n; i++)
{
varianza = varianza + (V[i]-media )*(V[i]-media );
}
cout << "La varianza del Vector es: " << varianza/(n-1) << endl;
varianza = varianza / (n - 1);
}
void calculardesviacionestandar(double varianza)
{
double desvi;
desvi = sqrt(varianza);
cout << "La desviancion estandar del vector es: " << desvi << endl;
}
void main()
{
double V[20], media, varianza;
int n;
leervector(V, n);
mostrarvector(V, n);
ordenarvector(V, n);
calcularmediana(V, n);
calcularsumamedia(V, n, media);
calcularvarianza(V, n, media,varianza);
calculardesviacionestandar(varianza);
system("pause");
}