Created
April 12, 2012 18:25
-
-
Save eloyesp/2369825 to your computer and use it in GitHub Desktop.
2do Taller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <stdio.h> | |
# define MAX 10 | |
int duplicado(int const vector[], int last); | |
int main(void) { | |
int i, vector[MAX]; | |
for (i = 0; i < MAX; i++) { | |
printf ("ingrese el valor: "); | |
scanf ("%d", &vector[i]); | |
while (duplicado(vector, i)) { | |
printf ("Ese numero ya esta, ingrese otro: "); | |
scanf ("%d", &vector[i]); | |
} | |
} | |
printf("\n"); | |
for (i=0; i < MAX; i++) | |
printf("%d ", vector[i]); | |
return 0; | |
} | |
int duplicado(int const vector[], int last_i) { | |
int duplicado = 0, i = 0, j; | |
while (!duplicado && i < last_i) { | |
j = i+1; | |
while (!duplicado && j <= last_i) { | |
duplicado = (vector[j] == vector[i]); | |
j++; | |
} | |
i++; | |
} | |
return duplicado; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <stdio.h> | |
# include <time.h> | |
# include <stdlib.h> | |
# define MAX 30 | |
# define REPETICIONES 800 | |
int main(void) { | |
int i, vector[MAX], n = 0; | |
srand(time(NULL)); | |
while (n < 1 || n > 30) { | |
printf ("Ingrese n entre 1 y 30: "); | |
scanf ("%d", &n); | |
} | |
for (i=0; i < n; i++) { | |
vector[i] = 0; | |
} | |
for (i=0; i < REPETICIONES; i++) { | |
vector[(int) (rand() % n)] ++; | |
} | |
for (i=0; i < n; i++) { | |
printf("%d: %d\n", i + 1, vector[i]); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define TAM 10 | |
int main( int argc, char *argv[] ) | |
{ | |
char opcion = 0; | |
int elementos[TAM], aux, i, ultimo = 0; | |
/*Menú de opciones*/ | |
printf("Ingrese la opcion deseada:\n"); | |
printf("a: Insertar elemento\n"); | |
printf("b: Eliminar elemento\n"); | |
printf("c: Eliminar posicion\n"); | |
printf("d: Buscar elemento\n"); | |
printf("e: Mostrar vector\n"); | |
printf("s: Salir:\n"); | |
opcion = getchar(); /* lee un caracter*/ | |
do{ | |
switch (opcion) { | |
case 'a': /* Inserta un elemento */ | |
printf("Ingrese elemento a insertar: "); | |
scanf("%d", &aux); | |
if (ultimo < TAM) | |
ultimo++; | |
for (i = ultimo; i > 0; i--) { | |
elementos[i] = elementos[i-1]; | |
} | |
elementos[0] = aux; | |
break; | |
case 'b': /* Busca un elemento y lo elimina*/ | |
printf("Ingrese elemento a eliminar: "); | |
scanf("%d",&aux); | |
break; | |
case 'c': /* Elimina el elemento de la posición seleccionada*/ | |
printf("Ingrese posicion de elemento a eliminar: "); | |
scanf("%d",&aux); | |
break; | |
case 'd': /* Busca un elemento y muestra en posición se encuentra */ | |
printf("Ingrese elemento a buscar: "); | |
scanf("%d",&aux); | |
break; | |
case 'e': /* Muestra vector */ | |
for (i = 0; i < ultimo; i++) | |
printf("%d ", elementos[i]); | |
printf("\n"); | |
break; | |
case 's': /* Salir */ | |
break; | |
default: printf("opcion equivocada!\n"); | |
} | |
printf("---------------\n"); | |
/*Menú de opciones*/ | |
printf("Ingrese la opcion deseada:\n"); | |
printf("a: Insertar elemento\n"); | |
printf("b: Eliminar elemento\n"); | |
printf("c: Eliminar posicion\n"); | |
printf("d: Buscar elemento\n"); | |
printf("e: Mostrar vector\n"); | |
printf("s: Salir:\n"); | |
fflush(stdin); /* limpia el buffer de entrada */ | |
opcion = getchar(); /* lee un caracter*/ | |
} while (opcion != 's'); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment