diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0f06797 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "stdio.h": "c" + } +} \ No newline at end of file diff --git a/Unidad 2-Estructuras de Control/Ejercicio8.py b/Unidad 2-Estructuras de Control/Ejercicio8.py index 631baad..ac8f405 100644 --- a/Unidad 2-Estructuras de Control/Ejercicio8.py +++ b/Unidad 2-Estructuras de Control/Ejercicio8.py @@ -18,4 +18,5 @@ elif aMult%bNum==0: print("Si es multiplo") else: - print("No es multiplo") \ No newline at end of file + print("No es multiplo") + \ No newline at end of file diff --git a/Unidad 2-Estructuras de Control/Prueba_1-7_C/pefmat-ejercicio2.c b/Unidad 2-Estructuras de Control/Prueba_1-7_C/pefmat-ejercicio2.c new file mode 100644 index 0000000..003f4fb --- /dev/null +++ b/Unidad 2-Estructuras de Control/Prueba_1-7_C/pefmat-ejercicio2.c @@ -0,0 +1,24 @@ +#include + +int main (){ + //Holi clase :v + + float aNum, bNum; + + scanf("%f",&aNum); + scanf("%f",&bNum); + + if (aNum > bNum){ + printf("%.1f > %.1f",aNum,bNum); + } + else if (aNum < bNum){ + printf("%.1f > %.1f",bNum,aNum); + + } + else{ + printf("Son iguales"); + } + + //Holi clase :v + return 0; +} diff --git a/Unidad 2-Estructuras de Control/Prueba_1-7_C/prueba_c.exe b/Unidad 2-Estructuras de Control/Prueba_1-7_C/prueba_c.exe new file mode 100644 index 0000000..58d8724 Binary files /dev/null and b/Unidad 2-Estructuras de Control/Prueba_1-7_C/prueba_c.exe differ diff --git a/Unidad 3-Funciones/Ejercicio1.c b/Unidad 3-Funciones/Ejercicio1.c new file mode 100644 index 0000000..f2511dd --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio1.c @@ -0,0 +1,49 @@ +//Autor: Jonathan Gómez +// Program that determines if an integer N number is even or odd +//Version 1.0 +#include + +int readNumber(int); +int calculateTypeNumber(int, int); +void printTypeNumber(int); + +int main(){ + int Number=0, typeNumber=0; + //Input: A integer Number + Number= readNumber(Number); + + //Process: Determines if the module of 2 of Number is 0, which means that is an even number + //Then the value of typeNumber change to 1, which for this program represents even and 0 represents odd + typeNumber= calculateTypeNumber(Number,typeNumber); + + //Output: 1 for even Number or 0 for odd Number + printTypeNumber(typeNumber); + +} + +int readNumber (int Number){ + //Read the number which want to know is even or odd and returns the value to the original variable Number + + scanf("%d", &Number); + + return Number; +} + +int calculateTypeNumber (int Number, int typeNumber){ + //Using the module function we compare the result with 0, that means _Number is even or odd + //The _typeNumber is even when the module give us 0 and odd when is >0, in the moment when the _Number + //is a even number the value of the flag change and if is not == 0 then the flag still being the same + //This function returns the value of _typeNumber because we are going to use it for the output + + typeNumber=0; + if (Number%2 == 0){ + typeNumber=1; + } + return typeNumber; +} + +void printTypeNumber(int typeNumber){ + //Using the value of _typeNumber we have the output of our program + + printf("%d", typeNumber); +} \ No newline at end of file diff --git a/Unidad 3-Funciones/Ejercicio1.py b/Unidad 3-Funciones/Ejercicio1.py new file mode 100644 index 0000000..614be41 --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio1.py @@ -0,0 +1,70 @@ +""" +Autor: Jonathan Gómez +Version 1.0 +Program that determines if an integer N number is even or odd +""" + +#Functions +def readNumber(): + """ + Read the number which want to know is even or odd and returns the value to the original variable Number + Args: + _Number: Read the number which the user wants to know if is even or odd + Returns: + _Number: The value entered + """ + _Number= int(input()) + + return _Number + +def calculateTypeNumber(_Number): + """ + Using the module function we compare the result with 0, that means _Number is even or odd + #The _typeNumber is even when the module give us 0 and odd when is >0, in the moment when the _Number + #is a even number the value of the flag change and if is not == 0 then the flag still being the same + #This function returns the value of _typeNumber because we are going to use it for the output + Args: + typeNumber: Flag who determinates the type of _Number + _Number: The value entered by the user + Returns: + _typeNumber: The type of number, even or odd + """ + _typeNumber=0 + if _Number%2==0 : + _typeNumber=1 + + return _typeNumber + +def printTypeNumber(_typeNumber): + """ + Using the value of _typeNumber we have the output of our program + Args: + _typeNumber: The final output with the type of number + """ + print(_typeNumber) + +def main(): + #Input + """ + Number (int): A integer Number + typeNumber (int): Type number, even or odd + """ + Number=0 + typeNumber=0 + Number=(readNumber()) + + #Process + """ + Determines if the module of 2 of Number is 0, which means that is an even number + Then the value of typeNumber change to 1, which for this program represents even and 0 represents odd + """ + typeNumber= calculateTypeNumber(Number) + + #Output + """ + 1 for even Number or 0 for odd Number + """ + printTypeNumber(typeNumber) + +if __name__== "__main__": + main() \ No newline at end of file diff --git a/Unidad 3-Funciones/Ejercicio13.c b/Unidad 3-Funciones/Ejercicio13.c new file mode 100644 index 0000000..4f3b1d6 --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio13.c @@ -0,0 +1,55 @@ +//Autor Irving Eduardo Poot Moo +//Version 1.0 +//Program who translate a militar hour to a normal hour + +#include + +int readHour(int); +char traduceHour(int, char); +int translateHour(int) +int translateMinutes(int) +void printHour(int, int, char) + + +int main(){ + // Entrada de la hora + int originalHour, hour, amPm, min; + originalHour = readHour(originalHour); + hour = traduceHour(originalHour); + min = translateMinutes(originalHour); + amPm = traduceHour(amPm, hour); + printHour(hour, min, amPm); +} + +// Reeds the hour +int readHour(int originalHour){ + scanf("%d",&originalHour); + return originalHour; +} + +int translateHour(int originalHour){ + hour = originalHour / 100; + return hour +} + +int translateMinutes(int originalHour){ + min = originalHour - (originalHour / 100 ) * 100 + return min +} + +// Translate the hour +char traduceHour(char amPm, int hour){ + + amPm= "am"; + if (hour > 12) { + hour = hour - 12; + amPm= "pm"; + } + return amPm +} + +void printHour(int hour, int min, char amPm){ + //Print the translated hour + printf("%1.2d : %1.2d %c", hour, min, amPm); + +} \ No newline at end of file diff --git a/Unidad 3-Funciones/Ejercicio13.py b/Unidad 3-Funciones/Ejercicio13.py new file mode 100644 index 0000000..891c66f --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio13.py @@ -0,0 +1,99 @@ +''' +Author Irving Eduardo Poot Moo +Version 1.0 +Program who translate a military hour to a normal hour +''' + + +def inputNumber(): + ''' + It gets the military hour that we will translate + Args: + N (int):Value of the military hour + Returns: + The original hour + ''' + N = 0 + N = int(input()) + return N + + +def timeTranslate(hours): + ''' + Determinate if the given hour is Am or Pm + Args: + amPm (char): Default time + hours (int): previously modified hour + Returns: + The modified time + ''' + amPm = "am" + if (hours > 12): + hours = hours - 12 + amPm = "pm" + + return amPm + +def hoursTranslate(time): + ''' + Gets the hours from the military time + Args: + time (int): The original hour + hours (int): The hours of the original hour + Returns: + The modified hours + ''' + hours = time // 100 + return hours + +def minutesTranslate(time): + ''' + Gets the minutes from the military time + Args: + time (int): The original hour + minutes (int): The minutes of the original hour + Returns: + The modified minutes + ''' + minutes = time - (time // 100)*100 + return minutes + +def printHour(hours, minutes, amPm): + ''' + Print the translated hour + Args: + hours (int): The hours of the original hour + minutes (int): The minutes of the original hour + amPm (char): Determinated time + Returns: + Nothing + ''' + print(str(hours).zfill(2)+":"+str(minutes).zfill(2)+ " " + amPm) + +#Input +''' +It recives the military hour + Args: + time (int): Given hour +''' + +time = inputNumber() + +#Process +''' +Translate the militry hour step by step, beggining from the time to the hours and finally the minutes + Args: + time (int): Given hour + hours (int): Translated hours + minutes (int): Translated minutes + amPM (char): Translated time +''' +hours = hoursTranslate(time) +minutes = minutesTranslate(time) +amPm = timeTranslate(time) + +#Output +''' +Print the translated hour +''' +printHour(hours, minutes, amPm) \ No newline at end of file diff --git a/Unidad 3-Funciones/Ejercicio19.c b/Unidad 3-Funciones/Ejercicio19.c index 7a1dff8..f9600a8 100644 --- a/Unidad 3-Funciones/Ejercicio19.c +++ b/Unidad 3-Funciones/Ejercicio19.c @@ -1,79 +1,64 @@ -/* - Autor: Carlos Chan Gongora 15/02/2019 - Entradas: Tres numeros. - Salidas: El mayor de los 3 numeros. - Procedimiento general: Lee los 3 numeros, posterior verifica si son iguales y encuentra - el mayor de los 3 numeros, si los numeros no son iguales imprime el mayor, de ser iguales - imprime un texto indicando que los numeros son iguales. -*/ -#include +//Autor Irving Eduardo Poot Moo +//Version 1.0 +//Program who compare two nombers and print the bigger -int entrada(); -int encontrarMayor(int, int, int); -int verificarIgualdad(int, int, int); -void imprimirResultados(int, int); +#include -int main(){ - // Entradas - int num1, num2, num3, mayor, igualdad; - num1 = entrada(); - num2 = entrada(); - num3 = entrada(); +float entrada1(); +float entrada2(); +float entrada3(); +float comparacion(float, float, float); +void imprimirMayor(float); - // Procesos - igualdad = verificarIgualdad(num1, num2, num3); - if(!igualdad){ - mayor = encontrarMayor(num1, num2, num3); - } +float main(){ + //Inputs + float num1, num2, num3; + float numMayor; + num1 = entrada1(); + num2 = entrada2(); + num3 = entrada3(); + // Process + comparacion(num1, num2, num3); + // Print number + imprimirMayor(numMayor); +} - // Salidas - imprimirResultados(igualdad, mayor); - return 0; +float entrada1(){ + float numero = 1; + scanf("%d",&numero); + return numero; } -// Lee un numero -int entrada(){ - int numero = 1; - printf("Ingrese un numero: "); - scanf("%d", &numero); - return numero; -} -// Verifica si los numeros son iguales, de ser verdad regresa 1 o de lo contrario regresa 0 -int verificarIgualdad(int num1, int num2, int num3){ - int igualdad = 0; - if(num1 == num2 && num2 == num3){ - igualdad = 1; - } - return igualdad; +float entrada2(){ + float numero = 1; + scanf("%d",&numero); + return numero; } -// Compara 3 numeros para encontrar el mayor -int encontrarMayor(int num1, int num2, int num3){ - int mayor = 0; - if((num1 > num2 && num1 > num3) || (num1 >= num2 && num1 >= num3)){ - mayor = num1; - } - else if(num2 > num1 && num2 > num3){ - mayor = num2; - } - else{ - mayor = num3; - } - return mayor; + +float entrada3(){ + float numero = 1; + scanf("%d",&numero); + return numero; } -// Verifica si los numeros son iguales, en ese caso imprime que "son iguales", -// de lo contrario imprime al mayor -void imprimirResultados(int igualdad, int mayor){ - if(igualdad){ - printf("Los numeros son iguales"); - } - else{ - printf("El mayor es: %d", mayor); - } + +float comparacion(float num1, float num2, float num3){ + float numMayor = 0; + if (num3 < num1 > num2) + { + numMayor = num1; + } + else if (num3 < num2 > num1) + { + numMayor = num2; + } + else + { + numMayor = num3; + } + return numMayor; } -/*AUTOR QA: RONSSON RAMIRO MAY SANTOS -ENTRADAS: 9,9, -3 -SALIDAS: EL MAYOR ES -3 -OBSERVACIONES: SOLO FUNCIONA CON NUMEROS POSITIVOS, CON UN NEGATIVO DICE QUE EL NEGATIVO ES EL MAYOR. -*/ +void imprimirMayor(float numMayor){ + printf("El numero mayor es: %d", numMayor); +} diff --git a/Unidad 3-Funciones/Ejercicio19.py b/Unidad 3-Funciones/Ejercicio19.py new file mode 100644 index 0000000..800f733 --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio19.py @@ -0,0 +1,97 @@ +''' +Author Irving Eduardo Poot Moo +Version 1.0 +Program who translate a military hour to a normal hour +''' + +def inputNum1(): + ''' + It gets the first number that we will compare + Args: + num1 (float): First given number + Retuns: + The fisrt number + ''' + num1 = float(input()) + return num1 + +def inputNum2(): + ''' + It gets the second number that we will compare + Args: + num2 (float): Second given number + Retuns: + The second number + ''' + num2 = float(input()) + return num2 + +def inputNum3(): + ''' + It gets the third number that we will compare + Args: + num3 (float): Third given number + Retuns: + The third number + ''' + num3 = float(input()) + return num3 + + +def comparisons(num1, num2, num3): + ''' + Compare all the numbers to get the biggest number + Args: + num1 (float): First given number + num2 (float): Second given number + num3 (float): Third given number + numMayor (float): The biggest number + Retuns: + The biggest number + ''' + if num1 > num2 and num1 > num3: + numMayor = num1 + elif num2 > num1 and num2 > num3: + numMayor = num2 + else: + numMayor = num3 + return (numMayor) + +def outputMayor(nunMayor): + ''' + Print the biggest number + Args: + numMayor (float): Second given number + Retuns: + Nothing + ''' + print("El numero mayor es: ", numMayor) + +#Inputs +''' +It recives the number to compare + Args: + num1 (float): First given number + num2 (float): Second given number + num3 (float): Third given number +''' +num1 = inputNum1() +num2 = inputNum2() +num3 = inputNum3() + +#Process +''' +Compares the tree given number to get the biggest + Args: + num1 (float): First given number + num2 (float): Second given number + num3 (float): Third given number + numMayor (float): The Biggest number +''' +numMayor = comparisons(num1, num2, num3) + +#Output +''' +Print the bigggest number +''' +outputMayor(numMayor) \ No newline at end of file diff --git a/Unidad 3-Funciones/Ejercicio25.c b/Unidad 3-Funciones/Ejercicio25.c new file mode 100644 index 0000000..43424d2 --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio25.c @@ -0,0 +1,40 @@ +//Author: Aldebaran Lira +//Program that finds the corresponding ASCII-code +//Version 1.0 + +#include + +//Function prototypes +void readLetter(char *); +int findASCIIcode(int); +void printCode(int); + +int main(){ + + // Declaration of variables + char letter; + int ASCIIc; + + //Input: A letter of the alphabet + readLetter(&letter); + + //Process: Find the ASCII-code + ASCIIc=(letter); + + //Output: The ASCII-code + printCode(ASCIIc); + + return 0; +} + +void readLetter(char *_letter){ + scanf("%c",_letter); getchar(); +} + +int findASCIIcode(int _ASCIIc){ + return _ASCIIc; +} + +void printCode(int _output){ + printf("%d\n\n",_output); +} diff --git a/Unidad 3-Funciones/Ejercicio25.py b/Unidad 3-Funciones/Ejercicio25.py new file mode 100644 index 0000000..37b67f6 --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio25.py @@ -0,0 +1,57 @@ +''' +Author: Aldebaran Lira +Version 0.0 +Find the ASCII-code +''' + +#Functions + +#Int +def readLetter(): + ''' + It reads a letter from the alphabet + Args: + _letter (str): Value of the variable + Returns: + A letter of the alphabet + ''' + _letter = str(input()) + + return _letter + +#Process +def findASCIIcode(_letter): + ''' + It searches for the corresponding code + Args: + _letter (str): A letter of the alphabet + _code (int): ASCII-code + Returns: + The correspondinf code + ''' + _code=ord(_letter) + + return _code + +#Output +def printResult(_code): + ''' + It prints the corresponding code + Args: + _code (int):The corresponding code + Returns: + Nothing + ''' + print(_code) + + +#Input +code=0 +letter=0 +letter=readLetter() + +#Process +code=findASCIIcode(letter) + +#Output +printResult(code) diff --git a/Unidad 3-Funciones/Ejercicio31.c b/Unidad 3-Funciones/Ejercicio31.c index 02cce49..b78e165 100644 --- a/Unidad 3-Funciones/Ejercicio31.c +++ b/Unidad 3-Funciones/Ejercicio31.c @@ -1,56 +1,57 @@ -/*Autor: Guillermo Canto Dzul -Entradas: Un numero entero -Salidas: Imprime si es primo o no -*/ - -#include -int entrada(); -int proceso(int n); -void salida(int n, int esPrimo); -int main(int argc, char *argv[]) { - int n, esPrimo; - n = entrada(); - esPrimo = proceso(n); - salida(n, esPrimo); - return 0; -} -//Lee el numero -int entrada(){ - int n; - printf("Ingrese un numero:\n"); - scanf("%d", &n ); - return n; -} -//Verifica si el numero es primo o no. -int proceso(int n){ - int suma = 0; - int i, flag; - for (i=1; i //Algoritmo en C donde introduzcas un número y te diga si es primo o no es primo; + +//Entrada | int numero; +//Procesos | Determinar si el número es primo o no; +//Salida || str "Es primo" or "No es primo" + +int read(); +int proceso (int esprimo); + +int main(){ //Función principal + + int num, es_Primo; + + num = read(); + es_Primo = proceso(num); + + if (es_Primo == 1){ //Condicion que determina si es primo o no el número + printf("Es primo"); + } + else{ + printf("No es primo"); + } + + return 0; } -//Imprime el resultado. -void salida(int n, int esPrimo){ - if (esPrimo == 1){ - printf("%d es primo\n", n); - } - else{ - printf("%d no es primo\n", n); - } + + +int read(){ //Función donde se lee la variable a determinar si es primo o no + + int num_Scan; + + scanf("%d",&num_Scan); + + return num_Scan; } -/*AUTOR QA : DANIEL DELFIN -ENTRADAS -1,2,17 -SALIDAS -1 NO ES UN NUMERO PRIMO - 2 ES UN NUMERO PRIMO - 17 ES UN NUMERO PRIMO -OBSERVACIONES. MUY BIEN LA MODULARIZACION DEL CODIGO*/ + +int proceso(int esprimo){ //Función donde se determina si el número se divide entre 2 números enteros nada más, recorriendo de 1 hasta ese núm con un ciclo for. + + int i, j, cont = 0; + + for (i = 1; i <= esprimo; i++){ + if (esprimo % i == 0){ + cont++; + } + } + + if (cont == 2){ + esprimo = 1; + } + else{ + esprimo = 0; + } + + return esprimo; +} \ No newline at end of file diff --git a/Unidad 3-Funciones/Ejercicio31.py b/Unidad 3-Funciones/Ejercicio31.py new file mode 100644 index 0000000..b95549f --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio31.py @@ -0,0 +1,28 @@ +# Autor: Farid Espadas Escalante + +# Entrada | numero entero; +# Procesos | determinar si el numero es primo o no +# Salida | str "Es primo" o "no es primo" + +def esprimo(numero_inicial): + if numero_inicial < 1: + return False + elif numero_inicial == 2: + return True + else: + for i in range (2, numero_inicial): + if numero_inicial % i == 0: + return False + return True + +# Entrada | leemos el numero +numero_inicial = int(input()) +salida = esprimo(numero_inicial) + +#Salida | imprime si es primo o no +if salida is True: + print("Es primo") +else: + print("No es primo") + + diff --git a/Unidad 3-Funciones/Ejercicio37.c b/Unidad 3-Funciones/Ejercicio37.c new file mode 100644 index 0000000..b4f2812 --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio37.c @@ -0,0 +1,58 @@ +//Autor: Farid Espadas Escalante +#include //Algoritmo en C que calcula la suma de los n primeros números primos, dandole n. + +//Entrada | int n; +//Procesos | Recorrer hasta encontrar los n números primos y hacer la sumatoria correspondiente. +//Salida | sumatoria de los n primeros números primos. + +int read_n(); +int sum(int num); + +int main(){ //Función principal + + int n, sum_n_prime; + + n = read_n(); + sum_n_prime = sum(n); + + printf("%d", sum_n_prime); + + return 0; + +} + +int read_n(){ //Función donde leemos la suma de los n primos a calcular + + int n_suma; + scanf("%d",&n_suma); + + return n_suma; + +} + + +int sum(int num){ //Función donde sucede la sumatoria, cada vez que encuentra un primo, lo suma. + + int i, j, n, suma = 0, es_primo = 1; + + for (i = 2; num > 0; i++) //a partir de dos están los primos + { + for (j = 2; j < i; j++) + { + if ( i % j == 0) + { + es_primo = 0; + break; + } + } + + if (es_primo) + { + suma += i; + num--; + } + es_primo = 1; + } + + return suma; +} diff --git a/Unidad 3-Funciones/Ejercicio37.py b/Unidad 3-Funciones/Ejercicio37.py new file mode 100644 index 0000000..14c200b --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio37.py @@ -0,0 +1,30 @@ +# Autor: Farid Espadas + +# Entrada | numero entero para saber cuantos primos sumar +# Salida | numero entero que sea la suma de los numeros primos + +#Funcion para saber si es primo o no +def esprimo(numero_Inicial): +#Primero consideramos si el número es menor que uno + if numero_Inicial < 1: + return False + elif numero_Inicial == 2: + return True + else: + for i in range (2, numero_Inicial): + if numero_Inicial % i == 0: + return False + return True + +n = input() #Leemos los n numeros primos a sumar +contador = 0 +i = 0 +suma_Primos = 0 + +while contador <= int(n): + if esprimo(i) is True: + contador = contador + 1 + suma_Primos = suma_Primos + int(i) + i = i + 1 + +print(suma_Primos) diff --git a/Unidad 3-Funciones/Ejercicio43.c b/Unidad 3-Funciones/Ejercicio43.c index d25edfb..2719240 100644 --- a/Unidad 3-Funciones/Ejercicio43.c +++ b/Unidad 3-Funciones/Ejercicio43.c @@ -1,130 +1,146 @@ /* - Autor: Raul Rivadeneyra - Entradas: Numeros enteros - Salidas: Cuantos numeros positivos y negativos hay - Proceso general: lee numeros enteros del usuario y si es positivo le suma uno al contador de positivos y lo similar - si es negativo. +Author Joshua Immanuel Meza Magana +Version 1.0 +Program who count how many positive and negative numbers are on N numbers, 0 break the count. */ -#include "stdio.h" +#include -void process(int*, int*); -char getNumbers(int*); -void checkSign(int, int*, int*); +void specifyNumbers(int *); +void inputNumbers(int,float[]); +int pResult(int,float[]); +int nResult(int,float[]); +void printResult(int,int); int main() { - int positive = 0; - int negative = 0; - //Da instrucciones al usuario - printf("Insert numbers to check how many positives or negatives are (type 0 to stop):\n"); + /* Input + It recives the N amount of numbers, and then it reads them. + Args: + nNum (int): Number of numbers + listNumbers (vector): List of numbers + */ + int nNum=0; + specifyNumbers(&nNum); + float listNumbers[nNum]; + inputNumbers(nNum,listNumbers); + + /*Process + Calculate how many positive and negative numbers are on the N numbers. + Args: + pos (int): Ammount of positive numbers + neg (int): Amount of negative numbers + N (int): Number of numbers + listNumbers (list): List of numbers + */ + int pos=0,neg=0; + pos=pResult(nNum,listNumbers); + neg=nResult(nNum,listNumbers); + + /*Output + Print the results. + */ + printResult(pos,neg); - //Proceso - process(&positive, &negative); - - //Imprime el resultado - printf("There are %d positive numbers and %d negative numbers\n", positive, negative); return 0; } -//Funciones// - -//Combina las funciones de getNumber y checkSign en un ciclo -void process(int *positive, int *negative) { - int number; - while (getNumbers(&number) == 0) { - checkSign(number, positive, negative); - } +/* Functions */ + +void specifyNumbers(int *_nNum){ + /* + It gets the N numbers that we will count. + Args: + _nNum (int): Value of the number of numbers + Returns: + The N numbers that will be counted + */ + scanf("%d",_nNum); + + if (*_nNum<0 || *_nNum==0){ + while (*_nNum<0 || *_nNum==0){ + scanf("%d",_nNum); + } + } } -/* - Lee numeros enteros y le asigna el valor directamente a la variable externa (paso por referencia), - si el numero es 0 entonces devuelve 1 para finalizar el ciclo donde se llamo, de lo contrario hace - return 0 por lo que sigue el ciclo -*/ -char getNumbers(int *number) { - scanf("%d", number); - if (*number == 0){ - return 1; - } - return 0; +void inputNumbers(int _nNum,float _listNumbers[]){ + /* + Get a vector of the numbers that we will compare. + Args: + _nNum (int): Number of numbers + _listNumbers (vector): The temporary list of numbers + con (int): Counter + Returns: + Values of the list of numbers + */ + int con=0; + + while (con<_nNum){ + scanf("%f",&_listNumbers[con]); + if (_listNumbers[con]==0){ + con=_nNum; + } + con+=1; + } } -//Evalua si el numero dado es postitivo o negativo y suma 1 a el asignado -void checkSign(int value, int *positive, int *negative) { - if (value > 0){ - *positive = *positive + 1; - } - else{ - *negative = * negative + 1; - } +int pResult(int _nNum,float _listNumbers[]){ + /* + It calculates the amount of positive numbers. + Args: + _nNum (int): Number of numbers + _listNumbers (vector): List of numbers + _pos (int): Ammount of positive numbers + Returns: + Ammount of positive numbers + */ + int _pos=0,i=0; + + while (i<_nNum){ + if (_listNumbers[i]==0){ + break; + } else if (_listNumbers[i]>0){ + _pos+=1; + } + i+=1; + } + + return _pos; } -/* -Autor: Raul Rivadeneyra -Entradas: Numeros enteros -Salidas: Cuantos numeros positivos y negativos hay -Proceso general: lee numeros enteros del usuario y si es positivo le suma uno al contador de positivos y lo similar -si es negativo. -*/ - -#include "stdio.h" - -void process(int*, int*); -char getNumbers(int*); -void checkSign(int, int*, int*); - -int main() { - int positive = 0; - int negative = 0; - - //Da instrucciones al usuario - printf("Insert numbers to check how many positives or negatives are (type 0 to stop):\n"); - - //Proceso - process(&positive, &negative); - - //Imprime el resultado - printf("There are %d positive numbers and %d negative numbers\n", positive, negative); - return 0; +int nResult(int _nNum,float _listNumbers[]){ + /* + It calculates the amount of negative numbers. + Args: + _nNum (int): Number of numbers + _listNumbers (vector): List of numbers + _neg (int): Ammount of negative numbers + Returns: + Ammount of negative numbers + */ + int _neg=0,i=0; + + while (i<_nNum){ + if (_listNumbers[i]==0){ + break; + } else if (_listNumbers[i]<0){ + _neg+=1; + } + i+=1; + } + + return _neg; } -//Funciones// - -//Combina las funciones de getNumber y checkSign en un ciclo -void process(int *positive, int *negative) { - int number; - while (getNumbers(&number) == 0) { - checkSign(number, positive, negative); - } -} - -/* -Lee numeros enteros y le asigna el valor directamente a la variable externa (paso por referencia), -si el numero es 0 entonces devuelve 1 para finalizar el ciclo donde se llamo, de lo contrario hace -return 0 por lo que sigue el ciclo -*/ -char getNumbers(int *number) { - scanf("%d", number); - if (*number == 0){ - return 1; - } - return 0; +void printResult(int _pos,int _neg){ + /* + It print the amount of positive and negative numbers + Args: + _pos (int): Copy of the value of the positive numbers + _neg (int): Copy of the value of the negative numbers + Returns: + Nothing + */ + printf("%d %d",_pos,_neg); } - -//Evalua si el numero dado es postitivo o negativo y suma 1 a el asignado -void checkSign(int value, int *positive, int *negative) { - if (value > 0){ - *positive = *positive + 1; - } - else{ - *negative = * negative + 1; - } -} - -/* -QA: Realizó: Jose Mendez -Entradas: (5, -6, 9, -7, 99, -99 , 0) -Salidas: 3 positivps y 3 negativos -Funciona Correctamente. -*/ diff --git a/Unidad 3-Funciones/Ejercicio43.py b/Unidad 3-Funciones/Ejercicio43.py new file mode 100644 index 0000000..437d589 --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio43.py @@ -0,0 +1,133 @@ +""" +Author Joshua Immanuel Meza Magana +Version 1.0 +Program who count how many positive and negative numbers are on N numbers, 0 break the count. +""" + +#Functions +def specifyNumbers(): + """ + It gets the N numbers that we will count. + Args: + _N (int): Value of the number of numbers + Returns: + The N numbers that will be counted + """ + _N=0 + + _N=int(input()) + + if _N<0: + while _N<0: + _N=int(input()) + + return _N + +def inputNumbers(_N): + """ + Get a vector of the numbers that we will compare. + Args: + _N (int): Number of numbers + _listNumbers (list): The temporary list of numbers + num (int): Variable where the user input the numbers + con (int): Counter + Returns: + Values of the list of numbers + """ + _listNumbers=[] + num=0 + con=0 + + while con<_N: + num=int(input()) + con=con+1 + + if num==0: + con=_N + else: + _listNumbers.append(num) + + return _listNumbers + +def pResult(_N,_listNumbers): + """ + It calculates the amount of positive numbers. + Args: + _N (int): Number of numbers + _listNumbers (list): List of numbers + _pos (int): Ammount of positive numbers + Returns: + Ammount of positive numbers + """ + _pos=0 + + for x in _listNumbers: + if x>0: + _pos=_pos+1 + + return _pos + +def nResult(_N,_listNumbers): + """ + It calculates the amount of negative numbers. + Args: + _N (int): Number of numbers + _listNumbers (list): List of numbers + _neg (int): Ammount of negative numbers + Returns: + Ammount of negative numbers + """ + _neg=0 + + for x in _listNumbers: + if x<0: + _neg=_neg+1 + + return _neg + + +def printResults(_pos,_neg): + """ + It print the amount of positive and negative numbers + Args: + _pos (int): Copy of the value of the positive numbers + _neg (int): Copy of the value of the negative numbers + Returns: + Nothing + """ + print(_pos) + print(_neg) + +def main(): + #Input + """ + It recives the N amount of numbers, and then it reads them. + Args: + N (int): Number of numbers + listNumbers (list): List of numbers + """ + N=0 + listNumbers=[] + N=specifyNumbers() + listNumbers.extend(inputNumbers(N)) + + #Process + """ + Calculate how many positive and negative numbers are on the N numbers. + Args: + pos (int): Ammount of positive numbers + neg (int): Amount of negative numbers + N (int): Number of numbers + listNumbers (list): List of numbers + """ + pos=pResult(N,listNumbers) + neg=nResult(N,listNumbers) + + #Output + """ + Print the results. + """ + printResults(pos,neg) + +if __name__=="__main__": + main() diff --git a/Unidad 3-Funciones/Ejercicio48.c b/Unidad 3-Funciones/Ejercicio48.c index d0a5baf..bf9525e 100644 --- a/Unidad 3-Funciones/Ejercicio48.c +++ b/Unidad 3-Funciones/Ejercicio48.c @@ -1,116 +1,125 @@ /* -Autor: Eyder Concha Moreno 16/Febrero/19 -Entradas: sueldo base, antiguedad en la empresa -Salidas: Incentivo, sueldo total y sueldo base, o error por entradas incorrectas - -Procedimiento general: -1.-Preguntamos el número de años de antiguedad -2.-Preguntamos antiguedad del empleado -3.-Verificamos si los datos ingresados son válidos -4.-Con su antiguedad, determinamos el porcentaje a otorgar -5.-Definimos el incentivo con el porcentaje obtenido -6.-Calculamos el sueldo total -7.-Asignamos un mensaje de salida de acuerdo a lo escrito por el usuario +Author Joshua Immanuel Meza Magana +Version 1.0 +Program who add a little amount of money to the salary of a worker depending on the time he has worked on the company. */ #include -#include -void entradas(float*, int*); -int validacionValores(float, int); -float calculoIncentivo(float, int); -float calculoSueldoTotal(float, float); -void salidas(int, float, float, float); - -int main() -{ - /*Entradas*/ - - float sueldoBase; - int antiguedad; - - float incentivo; - float sueldoTotal; - - int cantidadValida; - - /*Procedimiento*/ - printf("Ingresa el sueldo base y la antiguedad en la empresa respectivamente\n"); - entradas(&sueldoBase, &antiguedad); +int readAge(); +float readMoney(); +float calculateExtra(int,float); +void printResult(float); + +int main() { + + /*Input + It receives the values. + Args: + age (int): Age of the worker + money (float): Salary of the worker + total (float): New total amount of money + */ + int age=0; + float money=0,total=0; + age=readAge(); + money=readMoney(); + + /*Process + It calculates the new total. + Args: + age (int): Age of the worker + money (float): Salary of the worker + total (float): New total amount of money + */ + total=calculateExtra(age,money); + + /*Output + It prints the result. + Args: + total (float): New total amount of money + */ + printResult(total); + + return 0; +} - //Comprobamos si valores ingresados son validos - cantidadValida = validacionValores(sueldoBase, antiguedad); +/* Functions */ - //Determinamos incentivo y sueldo total - incentivo = calculoIncentivo(sueldoBase, antiguedad); - sueldoTotal = calculoSueldoTotal(sueldoBase, incentivo); +int readAge(){ + /* + It reads the age of the worker. + Args: + _age (int): Value of the age of the worker + Returns: + The age of the worker + */ + int _age=0; - //Con base a la validación, determinamos la salida - salidas(cantidadValida, sueldoTotal, sueldoBase, incentivo); + scanf("%d",&_age); - return 0; -} + if (_age<0 || _age>15 || _age==0){ + while (_age<0 || _age>15 || _age==0){ + scanf("%d",&_age); + } + } -void entradas(float* sueldoBase, int* antiguedad){ - scanf("%f", sueldoBase); - scanf("%d", antiguedad) !=2; + return _age; } -void salidas(int cantidadValida, float sueldoTotal, float sueldoBase, float incentivo){ - if(cantidadValida){ - printf("El sueldo total es de: $ %f \nEl sueldo base es de: $ %f \nEl incentivo es de: %f", sueldoTotal, sueldoBase, incentivo); - } else { - printf("Entrada invalida"); +float readMoney(){ + /* + It reads the salary of the worker. + Args: + _money (float): Salary of the worker + Returns: + The salary of the worker + */ + float _money=0; + + scanf("%f",&_money); + + if (_money<0){ + while (_money<0){ + scanf("%f",&_money); } -} + } -float calculoSueldoTotal(float sueldoBase, float incentivo){ - float suma = sueldoBase + incentivo; - return suma; + return _money; } -float calculoIncentivo(float sueldoBase, int antiguedad){ - float porcentajeIncentivo; - float incentivo; - - // Determinamos el incentivo con base a la antiguedad - if(antiguedad < 1){ - porcentajeIncentivo = 0; - - } else if(antiguedad < 4){ - porcentajeIncentivo = .01; - - } else if(antiguedad < 7){ - porcentajeIncentivo = .03; - - } else if(antiguedad < 10){ - porcentajeIncentivo = .05; - - } else { - porcentajeIncentivo = .07; - } - - incentivo = porcentajeIncentivo * sueldoBase; - return incentivo; +float calculateExtra(int _age,float _money){ + /* + It calculates the total new amount of money. + Args: + _age (int): Age of the worker + _money (float): Normal amount of money + _total (float): New total amount of money + Returns: + The new total amount of money + */ + float _total=0; + + if (_age>=1 && _age<=3){ + _total=_money*1.01; + } else if (_age>=4 && _age<=6){ + _total=_money*1.03; + } else if (_age>=7 && _age<=9){ + _total=_money*1.05; + } else if (_age>=10){ + _total=_money*1.07; + } + + return _total; } -int validacionValores(float sueldoBase, int antiguedad){ - // Se valida si las entradas leidas son validas - int cantidadValida = 1; - if(antiguedad <= 0 || sueldoBase <= 0){ - cantidadValida = 0; - } - return cantidadValida; +void printResult(float _total){ + /* + It prints the total of money. + Args: + _total (float): Total of money + Returns: + Nothing + */ + printf("%f",_total); } -/* -Autor QA: Jimmy Nathan Ojeda Arana -Entradas: 1000,8 -Salidas: El sueldo total es de: $ 1050.000000 El sueldo base es de: $ 1000.000000 El incentivo es de: 50.000000 -Proceso: OK -Modularización: OK. El main no puede estar más simple. - Función entradas: OK - Función validacionValores: OK - Función calculoIncentivo: OK - Función calculoSueldoTotal: OK - Función salidas: OK -*/ diff --git a/Unidad 3-Funciones/Ejercicio48.py b/Unidad 3-Funciones/Ejercicio48.py new file mode 100644 index 0000000..b3a08f3 --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio48.py @@ -0,0 +1,114 @@ +""" +Author Joshua Immanuel Meza Magana +Version 1.0 +Program who add a little amount of money to the salary of a worker +depending on the time he has worked on the company. +""" + +#Functions +def readAge(): + """ + It reads the age of the worker. + Args: + _age (Int): Value of the age of the worker + Returns: + The age of the worker + """ + _age=0 + + _age=int(input()) + + if _age<0 or _age>15 or _age==0: + while _age<0 or _age>15 or _age==0: + _age=int(input()) + + return _age + +def readMoney(): + """ + It reads the salary of the worker. + Args: + _money (Float): Salary of the worker + Returns: + The salary of the worker + """ + _money=0 + + _money=float(input()) + + if _money<0: + while _money<0: + _money=float(input()) + + return _money + +def calculateExtra(_age,_money): + """ + It calculates the total new amount of money. + Args: + _age (Int): Age of the worker + _money (Float): Normal amount of money + _total (Float): New total amount of money + Returns: + The new total amount of money + """ + _total=float(0) + + if _age>=1 and _age<=3: + _total=_money*1.01 + else: + if _age>=4 and _age<=6: + _total=_money*1.03 + else: + if _age>=7 and _age<=9: + _total=_money*1.05 + else: + _total=_money*1.07 + + return _total + +def printResult(_total): + """ + It prints the total of money. + Args: + _total (Float): Total of money + Returns: + Nothing + """ + print(_total) + +def main(): + #Input + """ + It receives the values. + Args: + age (Int): Age of the worker + money (Float): Salary of the worker + total (Float): New total amount of money + """ + age=0 + money=0 + total=0 + age=int(readAge()) + money=float(readMoney()) + + #Process + """ + It calculates the new total. + Args: + age (Int): Age of the worker + money (Float): Salary of the worker + total (Float): New total amount of money + """ + total=float(calculateExtra(age,money)) + + #Output + """ + It prints the result. + Args: + total (Float): New total amount of money + """ + printResult(total) + +if __name__=="__main__": + main() diff --git a/Unidad 3-Funciones/Ejercicio7.c b/Unidad 3-Funciones/Ejercicio7.c index d224a48..48234aa 100644 --- a/Unidad 3-Funciones/Ejercicio7.c +++ b/Unidad 3-Funciones/Ejercicio7.c @@ -1,54 +1,65 @@ -/* - Autor: Raul Rivadeneyra - Entradas: numeros positivos - Salidas: la adicion al numero ingresado respecto a ciertos factores - Proceso general: si el numero ingresado es mayor a 1000 o 3000 o 5000 aumenta cierta cantidad respectivamente - */ -#include "stdio.h" - -void getNumber(float*); -void moreThan1K(float*); -void moreThan3K(float*); -void moreThan5K(float*); - -int main() { - float number; - getNumber(&number); - moreThan1K(&number); - moreThan3K(&number); - moreThan5K(&number); - - printf("The outcome is: %f\n", number); - return 0; -} - -void getNumber(float *number) { - printf("Insert a positive number: "); - scanf("%f", number); - while (number <= 0) { - printf("The number isn\'t positive, try again: "); - scanf("%f", number); - } -} +//Autor: Jonathan Gómez +//Program that receives a positive number to which a percentage is added depending on its size. +//Version 1.0 -void moreThan1K(float *number) { - if (*number > 1000){ - *number += (*number * 0.05); - } -} +#include -void moreThan3K(float *number) { - if (*number > 3000){ - *number += (*number * 0.1); - } -} +//Function prototypes +int readNumber(int); +int calculatepercentage(int, int); +void printNewNumber(int); + +int main (){ + //Declaration of variables + int Number=0; + int newNumber=0; + + //Input:A integer Number and variable declarations + Number= readNumber(Number); + + //Process:With the help of another adding variable, its value is modified based on the number entered by the user + newNumber= calculatepercentage(newNumber, Number); + + //Output:The new value of newNumber, that is the result of the process + printNewNumber(newNumber); + + } + + int readNumber(int Number){ + //Read the number which is going to use to calculate the percentage the program will add + //Returns the Number value + + scanf("%d",&Number); + + return Number; + + } + + int calculatepercentage( int newNumber, int Number) { + //With if sentences the program determines how much percentage is going to add to the variable + //That percentage depends of how big is the number (1000=5%, 3000=10%, 5000=%5) + //The program would be add all the if sentences + + newNumber = Number; + if (Number>1000) { + newNumber+= Number*0.05; + } else { + if (Number>3000){ + newNumber+= Number*0.1; + } else { + if (Number>5000){ + newNumber+=Number*0.05; + } + } + } + + return newNumber; -void moreThan5K(float *number) { - if (*number > 5000){ - *number += (*number * 0.05); } -} -/* -QA: Hector Abraham V. Cosgalla -TODO MAL!! -*/ + + void printNewNumber(int newNumber){ + //Using the newNumber the program print the output + + printf("%d", newNumber); + + } \ No newline at end of file diff --git a/Unidad 3-Funciones/Ejercicio7.py b/Unidad 3-Funciones/Ejercicio7.py new file mode 100644 index 0000000..03f7450 --- /dev/null +++ b/Unidad 3-Funciones/Ejercicio7.py @@ -0,0 +1,78 @@ +""" +Autor: Jonathan Gómez +Program that receives a positive number to which a percentage is added depending on its size. +Version 1.0 +""" +#Functions +def readNumber (): + """ + Read the number which is going to use to calculate the percentage the program will add + Args: + _Number (int): Value of the user + Returns: + The read _Number entered by the user + """ + _Number=int(input()) + + return _Number + +def calculatepercentage (_Number): + """ + With if sentences the program determines how much percentage is going to add to the variable + That percentage depends of how big is the number (1000=5%, 3000=10%, 5000=%5) + The program would be add all the if sentences + Args: + _Number: Value entered + _newNumber: New number after increase percentage + Returns: + _newNumber: Final output + """ + _newNumber= _Number + + if _Number>1000: + _newNumber+= _Number*0.05 + elif (_Number>3000): + _newNumber+= _Number*0.1 + elif (_Number>5000): + _newNumber+= _Number*0.05 + + return _newNumber + +def printNewNumber(_newNumber): + """ + Using the _newNumber the program print the output + Args: + _newNumber: Value after increase percentage + """ + print(int(_newNumber)) + +def main(): +#Input + """ + A integer Number and variable declarations + Args: + Number (int): The number wich is going to use to calculate the new value + newNumber (int): The new value of the Number + """ + Number=0 + newNumber=0 + Number=readNumber() + + #Process + """ + With the help of another adding variable, its value is modified based on the number entered by the user + Args: + newNumber: The new value after increase percentage + """ + newNumber= calculatepercentage(Number) + + #Output + """ + The new value of newNumber, that is the result of the process + Args: + newNumber: Print the final output + """ + printNewNumber(newNumber) + +if __name__ == "__main__": + main() \ No newline at end of file