Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tareas/prueba.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
\documentclass[options]{article}

\begin{document}
hola mundo!
\end{document}
42 changes: 42 additions & 0 deletions tareas/tarea_3/busqueda_dos_en_dos/busqueda_dos_en_dos.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
#include <vector>
using namespace std;
int busquedaDosEnDos(const vector<int>& 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<int> 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;
}
Binary file not shown.
47 changes: 47 additions & 0 deletions tareas/tarea_3/busqueda_lineal/busqueda_lineal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <iostream>
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;
}
Binary file not shown.
9 changes: 9 additions & 0 deletions tareas/tarea_3/contar_hasta_10/contar_hasta_10.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>
using namespace std;

int main() {
for (int i = 1; i <= 10; i++) {
cout << i << "\n";
}
return 0;
}
Binary file not shown.
27 changes: 27 additions & 0 deletions tareas/tarea_3/contar_vocales/contar_vocales.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
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;
}
Binary file added tareas/tarea_3/contar_vocales/contar_vocales.exe
Binary file not shown.
29 changes: 29 additions & 0 deletions tareas/tarea_3/numero_primo/numero_primo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
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;
}
Binary file added tareas/tarea_3/numero_primo/numero_primo.exe
Binary file not shown.
99 changes: 99 additions & 0 deletions tareas/tarea_3/ordenamiento/ordenamiento.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include <iostream>
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;
}
Binary file added tareas/tarea_3/ordenamiento/ordenamiento.exe
Binary file not shown.
21 changes: 21 additions & 0 deletions tareas/tarea_3/suma_digitos/suma_digitos.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
#include <cstdlib>
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;
}
Binary file added tareas/tarea_3/suma_digitos/suma_digitos.exe
Binary file not shown.