Skip to content

Instantly share code, notes, and snippets.

@billowdood
Created March 7, 2015 05:22
Show Gist options
  • Save billowdood/193c067f334d4ad31e64 to your computer and use it in GitHub Desktop.
Save billowdood/193c067f334d4ad31e64 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void numeros(int random[20]);
int menu();
void todos(int random[20]);
void pares(int random[20]);
void impares(int random[20]);
void maxmin(int random[20]);
int main ()
{
int random[20], opcion;
numeros(random);
opcion=menu();
switch(opcion)
{
case 1:
todos(random);
break;
case 2:
pares(random);
break;
case 3:
impares(random);
break;
case 4:
maxmin(random);
break;
case 5:
printf("Adios!");
break;
}
}
void numeros(int random[20])
{
int i;
srand ( time(NULL) );
for(i=0; i<20; i++){
random[i]=rand();
}
}
int menu()
{
int opcion;
printf("1.Mostrar todos los numeros\n 2. mostrar pares\n 3.mostrar impares\n 4.mostrar max y min\n 5. salir\n");
scanf("%i", &opcion);
return opcion;
}
void todos(int random[20])
{
int i;
for(i=0; i<20; i++){
printf("Numero %d: %d\n",i,random[i]);
}
}
void pares(int random[20])
{
int i;
for(i=0; i<20; i++){
if(random[i]%2==0)
printf("en la Posicion:%i\n ", i);
printf("el numero es:%i\n", random[i]);
}
}
void impares(int random[20])
{
int i;
for(i=0; i<20; i++){
if(random[i]%2!=0)
printf("en la Posicion:%i\n ", i);
printf("el numero es:%i", random[i]);
}
}
void maxmin(int random[20])
{
int i, max, min;
for(i=1; i<20; i++){
if(random[i]>i)
max=random[i];
}
for(i=1; i<20; i++){
if(random[i]<i)
min=random[i];
}
printf("el numero maximo es: %i\n", max);
printf("el numero minimo es: %i\n", min);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment