-
Notifications
You must be signed in to change notification settings - Fork 0
/
Guia8Ejercicio6.cpp
66 lines (55 loc) · 1.03 KB
/
Guia8Ejercicio6.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
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#pragma argsused
#include <tchar.h>
#include <stdio.h>
#include <iostream>
using namespace std;
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <cstdlib>
#include <vector>
//Funcion para ordenar un vector
void ordenamientoBurbuja(int n[], int cantidad);
int _tmain(int argc, _TCHAR* argv[])
{
srand(time(NULL));
int n;
int c = 5;
int lista[c];
try{
printf("Indique la canditdad de datos a generar: ");
cin>>c;
if(c>0){
//Llenado del vector con numeros aleatorios
for(int i=0;i<c;i++){
n=1+rand()%(16-1);
lista[i]=n;
cout<<lista[i]<<endl;
}
ordenamientoBurbuja(lista,c);
for(int i=0;i<c;i++) cout<<lista[i]<<", ";
}
else throw 404;
}
catch(int e)
{
printf("Cantidad de datos no valida\t");
}
getch();
return 0;
}
void ordenamientoBurbuja(int n[], int cantidad){
int temp;
for(int i=0; i<cantidad;i++){
for(int j=0; j<cantidad; j++){
if(n[j]>n[j+1]){
temp = n[j];
n[j]=n[j+1];
n[j+1]=temp;
}
}
}
}