Skip to content

Instantly share code, notes, and snippets.

@alphanetEX
Created March 8, 2023 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alphanetEX/509fee019b06f4cddf1542867b6062cd to your computer and use it in GitHub Desktop.
Save alphanetEX/509fee019b06f4cddf1542867b6062cd to your computer and use it in GitHub Desktop.
manifiesto algoritmos
#include <stdio.h>
/* ingrese numeros mayores a 0 y vamos a calular el
- promedio de los numeros impares
- la cantidad de numeros mayoyes que a 24 y pares
- la sumatoria de los numeros primos
*/
void cargar(int vec[], int dim){
int cont=0, num=0, contPar=0, contImp=0, itemb=0;
while(cont < dim){
printf("Ingrese un numero: ");
scanf("%d", & num);
if(num%2 == 0 ){
vec[cont] = num;
contPar++;
} else if( num >= 24 && (num%2 !=0)){
vec[cont];
itemb++;
} else if(num%2 != 0) {
vec[cont] = num;
contImp++;
}
cont++;
}
//Contador de pruebas
printf("promedio de numeros impares: %d \n", contImp);
printf("numero mayores a 24 y impares: %d \n", itemb);
}
void second(){
int cont=0, num=0, contPar=0, contImp=0, itemb=0, cont_primos=0, cant_primos=0;
printf("Ingrese un numero: ");
scanf("%d", & num);
while(num !=0){
if(num%2 == 0 ){
contPar++;
} else if( num >= 24 && (num%2 !=0)){
itemb++;
} else if(num%2 != 0) {
contImp++;
}
cont_primos=0;
for (int i = 1; i <= num; i++){
if(num % i == 0){
cont_primos++;
}
}
if(cont_primos ==2){
printf("Es primo \n");
cant_primos++;
}
printf("Ingrese un numero: ");
scanf("%d", & num);
}
printf("promedio de numeros impares: %d \n", contImp);
printf("numero mayores a 24 y impares: %d \n", itemb);
printf("la cantidad de numeros primos es: %d \n", cant_primos);
}
int main(){
second();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment