diff --git a/tareas/prueba.tex b/tareas/prueba.tex new file mode 100644 index 0000000..4fbd3ba --- /dev/null +++ b/tareas/prueba.tex @@ -0,0 +1,5 @@ +\documentclass[options]{article} + +\begin{document} +hola mundo! +\end{document} \ No newline at end of file diff --git a/tareas/tarea_3/busqueda_dos_en_dos/busqueda_dos_en_dos.cpp b/tareas/tarea_3/busqueda_dos_en_dos/busqueda_dos_en_dos.cpp new file mode 100644 index 0000000..64590b6 --- /dev/null +++ b/tareas/tarea_3/busqueda_dos_en_dos/busqueda_dos_en_dos.cpp @@ -0,0 +1,42 @@ +#include +#include +using namespace std; +int busquedaDosEnDos(const vector& lista, int objetivo) { + int n = lista.size(); + for (int i = 0; i < n; i += 2) { + if (lista[i] == objetivo) { + return i; + } + if (i + 1 < n && lista[i + 1] == objetivo) { + return i + 1; + } + } + return -1; +} +int main() { + vector lista; + int n, x; + cout << "ingrese la cantidad de elementos: "; + cin >> n; + cout << "ingrese los elementos:\n"; + for (int i = 0; i < n; i++) { + cin >> x; + lista.push_back(x); + } + char continuar = 's'; + while (continuar == 's' || continuar == 'S') { + int objetivo; + cout << "\ningrese el numero a buscar: "; + cin >> objetivo; + int resultado = busquedaDosEnDos(lista, objetivo); + if (resultado != -1) { + cout << "objetivo encontrado en : " << resultado << endl; + } else { + cout << "objetivo no existe" << endl; + } + + cout << "\n desea buscar otro numero? (s/n): "; + cin >> continuar; + } + return 0; +} \ No newline at end of file diff --git a/tareas/tarea_3/busqueda_dos_en_dos/busqueda_dos_en_dos.exe b/tareas/tarea_3/busqueda_dos_en_dos/busqueda_dos_en_dos.exe new file mode 100644 index 0000000..8c408ff Binary files /dev/null and b/tareas/tarea_3/busqueda_dos_en_dos/busqueda_dos_en_dos.exe differ diff --git a/tareas/tarea_3/busqueda_lineal/busqueda_lineal.cpp b/tareas/tarea_3/busqueda_lineal/busqueda_lineal.cpp new file mode 100644 index 0000000..d87031e --- /dev/null +++ b/tareas/tarea_3/busqueda_lineal/busqueda_lineal.cpp @@ -0,0 +1,47 @@ +#include +using namespace std; + +// --------- BUSQUEDA LINEAL --------- +int busquedaLineal(int arr[], int n, int valor) { + for (int i = 0; i < n; i++) { + if (arr[i] == valor) { + return i; // retorna la posición donde se encontró + } + } + return -1; // no encontrado +} + +// --------- MAIN --------- +int main() { + int n, valor; + char repetir; + + do { + cout << "\nCantidad de datos: "; + cin >> n; + + int arr[1000]; + + cout << "Ingrese los datos:\n"; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + } + + cout << "\nIngrese el valor a buscar: "; + cin >> valor; + + int resultado = busquedaLineal(arr, n, valor); + + if (resultado != -1) { + cout << "Valor encontrado en la posicion: " << resultado << endl; + } else { + cout << "Valor no encontrado.\n"; + } + + cout << "\nDesea repetir? (s/n): "; + cin >> repetir; + + } while (repetir == 's' || repetir == 'S'); + + return 0; +} \ No newline at end of file diff --git a/tareas/tarea_3/busqueda_lineal/busqueda_lineal.exe b/tareas/tarea_3/busqueda_lineal/busqueda_lineal.exe new file mode 100644 index 0000000..05e7485 Binary files /dev/null and b/tareas/tarea_3/busqueda_lineal/busqueda_lineal.exe differ diff --git a/tareas/tarea_3/contar_hasta_10/contar_hasta_10.cpp b/tareas/tarea_3/contar_hasta_10/contar_hasta_10.cpp new file mode 100644 index 0000000..32ca739 --- /dev/null +++ b/tareas/tarea_3/contar_hasta_10/contar_hasta_10.cpp @@ -0,0 +1,9 @@ +#include +using namespace std; + +int main() { + for (int i = 1; i <= 10; i++) { + cout << i << "\n"; + } + return 0; +} \ No newline at end of file diff --git a/tareas/tarea_3/contar_hasta_10/contar_hasta_10.exe b/tareas/tarea_3/contar_hasta_10/contar_hasta_10.exe new file mode 100644 index 0000000..6167ba9 Binary files /dev/null and b/tareas/tarea_3/contar_hasta_10/contar_hasta_10.exe differ diff --git a/tareas/tarea_3/contar_vocales/contar_vocales.cpp b/tareas/tarea_3/contar_vocales/contar_vocales.cpp new file mode 100644 index 0000000..99a010d --- /dev/null +++ b/tareas/tarea_3/contar_vocales/contar_vocales.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; +int contarVocales(string texto) { + int contar = 0; + for (char x : texto) { + x = tolower(x); + if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') { + contar++; + } + } + return contar; +} +int main() { + string oracion; + char continuar; + do { + cout << "ingrese una oracion: "; + getline(cin, oracion); + int total = contarVocales(oracion); + cout << "total de vocales: " << total << endl; + cout << "desea ingresar otra oracion? (s/n): "; + cin >> continuar; + cin.ignore(); + } while (continuar == 's' || continuar == 'S'); + cout << "programa terminado." << endl; + return 0; +} \ No newline at end of file diff --git a/tareas/tarea_3/contar_vocales/contar_vocales.exe b/tareas/tarea_3/contar_vocales/contar_vocales.exe new file mode 100644 index 0000000..28481c4 Binary files /dev/null and b/tareas/tarea_3/contar_vocales/contar_vocales.exe differ diff --git a/tareas/tarea_3/numero_primo/numero_primo.cpp b/tareas/tarea_3/numero_primo/numero_primo.cpp new file mode 100644 index 0000000..524ee00 --- /dev/null +++ b/tareas/tarea_3/numero_primo/numero_primo.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +bool esprimo(int x) { + if (x <= 1) return false; + if (x == 2) return true; + for (int i = 2; i * i <= x; i++) { + if (x % i == 0) { + return false; + } + } + return true; +} +int main() { + int numero; + char continuar; + do { + cout << "ingrese un numero: "; + cin >> numero; + if (esprimo(numero)) { + cout << "primo" << endl; + } else { + cout << "no primo" << endl; + } + cout << "desea ingresar otro numero? (s/n): "; + cin >> continuar; + } while (continuar == 's' || continuar == 'S'); + cout << "programa terminado." << endl; + return 0; +} \ No newline at end of file diff --git a/tareas/tarea_3/numero_primo/numero_primo.exe b/tareas/tarea_3/numero_primo/numero_primo.exe new file mode 100644 index 0000000..18b580b Binary files /dev/null and b/tareas/tarea_3/numero_primo/numero_primo.exe differ diff --git a/tareas/tarea_3/ordenamiento/ordenamiento.cpp b/tareas/tarea_3/ordenamiento/ordenamiento.cpp new file mode 100644 index 0000000..a842863 --- /dev/null +++ b/tareas/tarea_3/ordenamiento/ordenamiento.cpp @@ -0,0 +1,99 @@ +#include +using namespace std; +// bubble +void bubble(int arr[], int n) { + for (int x = 0; x < n - 1; x++) { + for (int y = 0; y < n - x - 1; y++) { + if (arr[y] > arr[y + 1]) { + swap(arr[y], arr[y + 1]); + } + } + } +} +// seleccion +void Selection(int arr[], int n) { + for (int x = 0; x < n - 1; x++) { + int min = x; + for (int y = x + 1; y < n; y++) { + if (arr[y] < arr[min]) { + min = y; + } + } + swap(arr[x], arr[min]); + } +} +// merge sort +void merge(int arr[], int start, int medium, int end) { + int x = start, y = medium + 1, z = 0; + int temp[100]; + while (x <= medium && y <= end) { + if (arr[x] < arr[y]) { + temp[z++] = arr[x++]; + } else { + temp[z++] = arr[y++]; + } + } + while (x <= medium) { + temp[z++] = arr[x++]; + } + while (y <= end) { + temp[z++] = arr[y++]; + } + for (int x = start, y = 0; x <= end; x++, y++) { + arr[x] = temp[y]; + } +} +void mergesort(int arr[], int start, int end) { + if (start < end) { + int medium = (start + end) / 2; + mergesort(arr, start, medium); + mergesort(arr, medium + 1, end); + merge(arr, start, medium, end); + } +} +// --------- MOSTRAR --------- +void mostrar(int arr[], int n) { + for (int x = 0; x < n; x++) { + cout << arr[x] << " "; + } + cout << endl; +} +// --------- MAIN --------- +int main() { + int opcion, n; + char repetir; + do { + cout << "\nCantidad de datos: "; + cin >> n; + int arr[1000]; + cout << "Ingrese los datos:\n"; + for (int x = 0; x < n; x++) { + cin >> arr[x]; + } + cout << "\nMetodos de ordenamiento:\n"; + cout << "1. bubble\n"; + cout << "2. Selection\n"; + cout << "3. Merge Sort\n"; + cout << "Elija una opcion: "; + cin >> opcion; + switch (opcion) { + case 1: + bubble(arr, n); + break; + case 2: + Selection(arr, n); + break; + case 3: + mergesort(arr, 0, n - 1); + break; + default: + cout << "Opcion invalida\n"; + continue; + } + cout << "\nArreglo ordenado:\n"; + mostrar(arr, n); + cout << "\nDesea repetir? (s/n): "; + cin >> repetir; + } while (repetir == 's' || repetir == 'S'); + return 0; +} \ No newline at end of file diff --git a/tareas/tarea_3/ordenamiento/ordenamiento.exe b/tareas/tarea_3/ordenamiento/ordenamiento.exe new file mode 100644 index 0000000..0f2702b Binary files /dev/null and b/tareas/tarea_3/ordenamiento/ordenamiento.exe differ diff --git a/tareas/tarea_3/suma_digitos/suma_digitos.cpp b/tareas/tarea_3/suma_digitos/suma_digitos.cpp new file mode 100644 index 0000000..dcd22a8 --- /dev/null +++ b/tareas/tarea_3/suma_digitos/suma_digitos.cpp @@ -0,0 +1,21 @@ +#include +#include +using namespace std; +int main() { + char continuar; + do { + int x, suma = 0; + cout << " ingresa un numero entero: "; + cin >> x; + x = abs(x); + while (x > 0) { + suma += x % 10; + x /= 10; + } + cout << "La suma de los digitos es: " << suma << endl; + cout << "deseas volverlo a intentar? (s/n): "; + cin >> continuar; + } while (continuar == 's' || continuar == 'S'); + cout << "programa terminado." << endl; + return 0; +} \ No newline at end of file diff --git a/tareas/tarea_3/suma_digitos/suma_digitos.exe b/tareas/tarea_3/suma_digitos/suma_digitos.exe new file mode 100644 index 0000000..85c9728 Binary files /dev/null and b/tareas/tarea_3/suma_digitos/suma_digitos.exe differ