diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.1/Programa 3.1.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.1/Programa 3.1.c new file mode 100644 index 0000000..c5d696d --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.1/Programa 3.1.c @@ -0,0 +1,21 @@ +#include +/* Nómina. +El programa, al recibir los salarios de 15 profesores, obtiene el total de la +➥nómina de la universidad. + +I: variable de tipo entero. +SAL y NOM: variables de tipo real. */ + +void main(void) +{ + int I; + float SAL, NOM; + NOM = 0; + for (I = 1; I <= 15; I++) + { + printf("\nIngrese el salario del profesor % d:\t", I); + scanf("%f", &SAL); + NOM = NOM + SAL; + } + printf("\nEl total de la nómina es: %.2f", NOM); +} diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.10/Programa 3.10.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.10/Programa 3.10.c new file mode 100644 index 0000000..8ceb790 --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.10/Programa 3.10.c @@ -0,0 +1,39 @@ +#include +#include +#include + +/* Pares e impares. +El programa, al recibir como datos N números enteros, obtiene la suma de los +➥números pares y calcula el promedio de los impares. + +I, N, NUM, SPA, SIM, CIM: variables de tipo entero. */ + +void main(void) +{ + int I, N, NUM, SPA = 0, SIM = 0, CIM = 0; + + printf("Ingrese el numero de datos que se van a procesar: \t"); + scanf("%i", &N); + if (N > 0) + { + for (I = 1; I <= N; I++) + { + printf("\nIngrese el numero %i: ", I); + scanf("%i", &NUM); + if (NUM) + if (pow(-1, NUM) > 0) + SPA = SPA + NUM; + else + { + SIM = SIM + NUM; + CIM++; + } + } + printf("\n La suma de los numeros pares es: %d", SPA); + printf("\n El promedio de numeros impares es: %.2f", (float)(SIM / CIM)); + } + else + printf("\n El valor de N es incorrecto"); + + system("pause"); +} \ No newline at end of file diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.11/Programa 3.11.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.11/Programa 3.11.c new file mode 100644 index 0000000..14378a3 --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.11/Programa 3.11.c @@ -0,0 +1,39 @@ +#include + +/* Examen de admisión. +El programa, al recibir como datos una serie de calificaciones de un examen, +➥obtiene el rango en que se encuentran estas. + +R1, R2, R3, R4 y R5: variable de tipo entero. +CAL: variable de tipo real. */ + +void main(void) +{ + int R1 = 0, R2 = 0, R3 = 0, R4 = 0, R5 = 0; + float CAL; + printf("Ingresa la calificacion del alumno: "); + scanf("%f", &CAL); + while (CAL != -1) + { + if (CAL < 4) + R1++; + else + if (CAL < 6) + R2++; + else + if (CAL < 8) + R3++; + else + if (CAL < 9) + R4++; + else + R5++; + printf("Ingresa la calificacion del alumno: "); + scanf("%f", &CAL); + } + printf("\n0..3.99 = %d", R1); + printf("\n4..5.99 = %d", R2); + printf("\n6..7.99 = %d", R3); + printf("\n8..8.99 = %d", R4); + printf("\n9..10 = %d", R5); +} \ No newline at end of file diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.12/Programa 3.12.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.12/Programa 3.12.c new file mode 100644 index 0000000..48c0520 --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.12/Programa 3.12.c @@ -0,0 +1,30 @@ +#include +#include + +/* Serie de ULAM. +El programa, al recibir como dato un entero positivo, obtiene y escribe +➥la serie de ULAM. + +NUM: variable de tipo entero. */ + +void main(void) +{ + int NUM; + printf("Ingresa el número para calcular la serie: "); + scanf("%d", &NUM); + if (NUM > 0) + { + printf("\nSerie de ULAM\n"); + printf("%d \t", NUM); + while (NUM != 1) + { + if (pow(-1, NUM) > 0) + NUM = NUM / 2; + else + NUM = NUM * 3 + 1; + printf("%d \t", NUM); + } + } + else + printf("\n NUM debe ser un entero positivo"); +} diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.13/Programa 3.13.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.13/Programa 3.13.c new file mode 100644 index 0000000..7f18c2b --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.13/Programa 3.13.c @@ -0,0 +1,19 @@ +#include + +/* Fibonacci. +El programa calcula y escribe los primeros 50 números de Fibonacci. + +I, PRI, SEG, SIG: variables de tipo entero. */ + +void main(void) +{ + int I, PRI = 0, SEG = 1, SIG; + printf("\t%i \t %i", PRI, SEG); + for (I = 3; I <= 50; I++) + { + SIG = PRI + SEG; + PRI = SEG; + SEG = SIG; + printf("\t %i", SIG); + } +} diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.14/Programa 3.14.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.14/Programa 3.14.c new file mode 100644 index 0000000..2d70477 --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.14/Programa 3.14.c @@ -0,0 +1,45 @@ +#include +/* Elección. +El programa obtiene el total de votos de cada candidato y el porcentaje +➥correspondiente. También considera votos nulos. + +VOT, C1, C2, C3, C4, C5, NU, SVO: variables de tipo entero. +PO1, PO2, PO3, PO4, PO5, PON: variables de tipo real.*/ + +void main(void) +{ + int VOT, C1 = 0, C2 = 0, C3 = 0, C4 = 0, C5 = 0, NU = 0, SVO; + float PO1, PO2, PO3, PO4, PO5, PON; + printf("Ingrese el primer voto: "); + scanf("%d", &VOT); + + while (VOT) + { + switch (VOT) + { + case 1: C1++; break; + case 2: C2++; break; + case 3: C3++; break; + case 4: C4++; break; + case 5: C5++; break; + default: NU++; break; + } + printf("Ingrese el siguiente voto –0 para terminar–: "); + scanf("%d", &VOT); + } + SVO = C1 + C2 + C3 + C4 + C5 + NU; + PO1 = ((float)C1 / SVO) * 100; + PO2 = ((float)C2 / SVO) * 100; + PO3 = ((float)C3 / SVO) * 100; + PO4 = ((float)C4 / SVO) * 100; + PO5 = ((float)C5 / SVO) * 100; + PON = ((float)NU / SVO) * 100; + + printf("\nTotal de votos: %d", SVO); + printf("\n\nCandidato 1: %d votos -- Porcentaje: %.2f", C1, PO1); + printf("\nCandidato 2: %d votos -- Porcentaje: %.2f", C2, PO2); + printf("\nCandidato 3: %d votos -- Porcentaje: %.2f", C3, PO3); + printf("\nCandidato 4: %d votos -- Porcentaje: %.2f", C4, PO4); + printf("\nCandidato 5: %d votos -- Porcentaje: %.2f", C5, PO5); + printf("\nNulos: %d votos -- Porcentaje: %.2f", NU, PON); +} diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.15/Programa 3.15.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.15/Programa 3.15.c new file mode 100644 index 0000000..d2dc82e --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.15/Programa 3.15.c @@ -0,0 +1,36 @@ +#include +#include +#include + +/* Cálculo de P. +El programa obtiene el valor de P aplicando una serie determinada. + +I, B, C: variables de tipo entero. +RES: variable de tipo real de doble precisión. */ + +void main(void) +{ + int I = 1, B = 0, C; + double RES; + RES = 4.0 / I; + C = 1; + + while ((fabs(3.1415 - RES)) > 0.0005) + { + I += 2; + if (B) + { + RES += (double)(4.0 / I); + B = 0; + } + else + { + RES -= (double)(4.0 / I); + B = 1; + } + C++; + } + printf("\nNumero de terminos: %d\n", C); + + system("pause"); +} \ No newline at end of file diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.16/Programa 3.16.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.16/Programa 3.16.c new file mode 100644 index 0000000..e770326 --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.16/Programa 3.16.c @@ -0,0 +1,46 @@ +#include + +/* Calificaciones. +El programa, al recibir un grupo de calificaciones de un alumno, obtiene el promedio de calificaciones de cada uno de ellos y, además, los alumnos con el mejor +y peor promedio. + +I, MAT, MAMAT y MEMAT: variables de tipo entero. +CAL, SUM, MAPRO, MEPRO y PRO: variables de tipo real.*/ + +void main(void) +{ + int I, MAT, MAMAT, MEMAT; + float SUM, PRO, CAL, MAPRO = 0.0, MEPRO = 11.0; + printf("Ingrese la matricula del primer alumno: \t"); + scanf("%d", &MAT); + + while (MAT) + { + SUM = 0; + for (I = 1; I <= 5; I++) + { + printf("\tIngrese la calificacion del alumno: ", I); + scanf("%f", &CAL); + SUM += CAL; + } + PRO = SUM / 5; + + printf("\nMatricula: %i\tPromedio: %.2f", MAT, PRO); + + if (PRO > MAPRO) + { + MAPRO = PRO; + MAMAT = MAT; + } + if (PRO < MEPRO) + { + MEPRO = PRO; + MEMAT = MAT; + } + + printf("\n\nIngrese la matricula del siguiente alumno: "); + scanf("%i", &MAT); + } + printf("\n\nAlumno con mejor Promedio: \t %i\t\ %.2f", MAMAT, MAPRO); + printf("\n\nAlumno con peor Promedio : \t %i\t\ %.2f", MEMAT, MEPRO); +} diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.17/Programa 3.17.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.17/Programa 3.17.c new file mode 100644 index 0000000..e261b1e --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.17/Programa 3.17.c @@ -0,0 +1,30 @@ +#include +#include + +/* Números perfectos. +El programa, al recibir como dato un número entero positivo como límite, obtiene +los números perfectos que hay entre 1 y ese número, y además imprime cuántos números perfectos hay en el intervalo. + +I, J, NUM, SUM, C: variables de tipo entero. */ + +void main(void) +{ + int I, J, NUM, SUM, C = 0; + printf("\nIngrese el numero limite: "); + scanf("%d", &NUM); + + for (I = 1; I <= NUM; I++) + { + SUM = 0; + for (J = 1; J <= (I / 2); J++) + if ((I % J) == 0) + SUM += J; + if (SUM == I) + { + printf("\n%i es un numero perfecto", I); + C++; + } + } + printf("\nEntre 1 y %i hay %i numeros perfectos\n", NUM, C); + system("pause"); +} diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.2/Programa 3.2.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.2/Programa 3.2.c new file mode 100644 index 0000000..6886056 --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.2/Programa 3.2.c @@ -0,0 +1,23 @@ +#include + +/* Suma positivos. +El programa, al recibir como datos N números enteros, obtiene la suma de los +➥enteros positivos. + +I, N, NUM, SUM: variables de tipo entero. */ + +void main(void) +{ + int I, N, NUM, SUM; + SUM = 0; + printf("Ingrese el número de datos: \t"); + scanf("%d", &N); + for (I = 1; I <= N; I++) + { + printf("Ingrese el dato número %d: \t", I); + scanf("%d", &NUM); + if (NUM > 0) + SUM = SUM + NUM; + } + printf("\nLa suma de los números positivos es: %d", SUM); +} diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.3/Programa 3.3.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.3/Programa 3.3.c new file mode 100644 index 0000000..bc68f7b --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.3/Programa 3.3.c @@ -0,0 +1,26 @@ +#include + +/* Suma pagos. +El programa, al recibir como datos un conjunto de pagos realizados en el último +➥mes, obtiene la suma de los mismos. + +PAG y SPA: variables de tipo real. */ + +void main(void) +{ + float PAG, SPA; + SPA = 0; + + printf("Ingrese el primer pago: \t"); + scanf("%f", &PAG); + + while (PAG) + /* Observa que la condición es verdadera mientras el pago es diferente de cero. */ + { + SPA = SPA + PAG; + printf("Ingrese el siguiente pago: \t"); + scanf("%f", &PAG); + /* Observa que la proposición que modifica la condición es una lectura. */ + } + printf("\nEl total de pagos del mes es: %.2f", SPA); +} diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.4/Programa 3.4.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.4/Programa 3.4.c new file mode 100644 index 0000000..01bc5ed --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.4/Programa 3.4.c @@ -0,0 +1,25 @@ +#include +#include + +/* Suma cuadrados. +El programa, al recibir como datos un grupo de enteros positivos, obtiene el +➥cuadrado de los mismos y la suma correspondiente a dichos cuadrados. */ + +void main(void) +{ + int NUM; + long CUA, SUC = 0; + + printf("\nIngrese un número entero - 0 para terminar -: \t"); + scanf("%d", &NUM); + while (NUM) + /* Observa que la condición es verdadera mientras el entero es diferente de cero. */ + { + CUA = pow(NUM, 2); + printf("%d al cubo es %ld", NUM, CUA); + SUC = SUC + CUA; + printf("\nIngrese un número entero - 0 para terminar -: \t"); + scanf("%d", &NUM); + } + printf("\nLa suma de los cuadrados es %ld", SUC); +} diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.5/Programa 3.5.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.5/Programa 3.5.c new file mode 100644 index 0000000..0b3557b --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.5/Programa 3.5.c @@ -0,0 +1,21 @@ +#include + +/* Suma pagos. +El programa obtiene la suma de los pagos realizados el último mes. + +PAG y SPA: variables de tipo real.*/ + +void main(void) +{ + float PAG, SPA = 0; + printf("Ingrese el primer pago: \t"); + scanf("%f", &PAG); + /* Observa que al utilizar la estructura do-while al menos se necesita un pago.*/ + do + { + SPA = SPA + PAG; + printf("Ingrese el siguiente pago - 0 para terminar -: \t "); + scanf("%f", &PAG); + } while (PAG); + printf("\nEl total de pagos del mes es: %.2f", SPA); +} \ No newline at end of file diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.6/Programa 3.6.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.6/Programa 3.6.c new file mode 100644 index 0000000..7239df4 --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.6/Programa 3.6.c @@ -0,0 +1,28 @@ +#include + +/* Nómina de profesores. +El programa, al recibir como datos los salarios de los profesores de una +➥universidad, obtiene la nómina y el promedio de los salarios. + +I: variable de tipo entero. + +SAL, NOM y PRO: variables de tipo real. */ + +void main(void) +{ + int I = 0; + float SAL, PRO, NOM = 0; + printf("Ingrese el salario del profesor: \t"); + /* Observa que al menos se necesita ingresar el salario de un profesor para que + ➥no ocurra un error de ejecución del programa. */ + scanf("%f", &SAL); + do + { + NOM = NOM + SAL; + I = I + 1; + printf("Ingrese el salario del profesor.\n- 0 para terminar - : \t"); + scanf("%f", &SAL); + } while (SAL); + PRO = NOM / I; + printf("\nNómina: %.2f \t Promedio de salarios: % .2f", NOM, PRO); +} diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.7/Programa 3.7.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.7/Programa 3.7.c new file mode 100644 index 0000000..0acfc49 --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.7/Programa 3.7.c @@ -0,0 +1,30 @@ +#include + +/* Lanzamiento de martillo. +El programa, al recibir como dato N lanzamientos de martillo, calcula el promedio +➥de los lanzamientos de la atleta cubana. + +I, N: variables de tipo entero. +LAN, SLA: variables de tipo real. */ + +void main(void) +{ + int I, N; + float LAN, SLA = 0; + do + { + printf("Ingrese el numero de lanzamientos: \t"); + scanf("%d", &N); + + } while (N < 1 || N > 11); + /* Se utiliza la estructura do-while para verificar que el valor de N sea + ➥correcto. */ + for (I = 1; I <= N; I++) + { + printf("\nIngrese el lanzamiento %d: ", I); + scanf("%f", &LAN); + SLA = SLA + LAN; + } + SLA = SLA / N; + printf("\nEl promedio de lanzamientos es: %.2f", SLA); +} \ No newline at end of file diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.8/Programa 3.8.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.8/Programa 3.8.c new file mode 100644 index 0000000..ab49733 --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.8/Programa 3.8.c @@ -0,0 +1,23 @@ +# include +/* Factorial. +El programa calcula el factorial de un número entero. + +FAC, I, NUM: variables de tipo entero. */ +void main(void) +{ + int I, NUM; + long FAC; + printf("\nIngrese el numero: "); + scanf("%i", &NUM); + if (NUM >= 0) + { + FAC = 1; + + for (I = 1; I <= NUM; I++) + + FAC *= I; + printf("\El factorial de %i es: %ld", NUM, FAC); + } + else + printf("\nError en el dato ingresado"); +} \ No newline at end of file diff --git a/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.9/Programa 3.9.c b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.9/Programa 3.9.c new file mode 100644 index 0000000..80523da --- /dev/null +++ b/3. Estructuras algoritmicas repetitivas/Programas/Programa 3.9/Programa 3.9.c @@ -0,0 +1,31 @@ +#include +#include + +/* Serie. +El programa imprime los términos y obtiene la suma de una determinada serie. + +I, SSE y CAM: variable de tipo entero. */ + +void main(void) +{ + int I = 2, CAM = 1; + long SSE = 0; + while (I <= 2500) + { + SSE = SSE + I; + printf("\t %i", I); + if (CAM) + { + I += 5; + CAM--; + } + else + { + I += 3; + CAM++; + } + } + printf("\nLa suma de la serie es: %ld", SSE); + + system("pause"); +} \ No newline at end of file