Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ej 2 c3
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> bool buscar(int *,int,int); int * insertar(int *,int *,int); void ordenar(int *,int); void mostrar(int *,int); int main() { int *vector = NULL; int dato; int largo = 0; do { scanf("%d",&dato); if (dato == 0) break; vector = insertar(vector,&largo,dato); if (vector == NULL) return 1; } while (true); ordenar(vector,largo); mostrar(vector,largo); return 0; } bool buscar(int *A, int largo, int dato) { int i; for (i = 0 ; i < largo ; i++) if (A[i] == dato) return true; return false; } int *insertar(int *A,int *largo,int dato) { int N = (*largo); bool esta = buscar(A,N,dato); if (esta == false) //NO ESTA { A = (int *) realloc(A,sizeof(int)*(N+1)); if (A == NULL) return NULL; A[N] = dato; N++; } (*largo) = N; return A; } void mostrar(int *A,int largo) { int i; printf("VECTOR = { "); for (i = 0 ; i < largo; i++) printf("%d ",A[i]); printf("}\n"); } void ordenar(int *A,int largo) { int i,k; int temporal; int flag = 0; for (i = 0 ; i < largo - 1 ; i++) { for (k = 0 ; k < (largo - 1) - i ; k++) { if (A[k] > A[k+1]) { flag = 1; temporal = A[k]; A[k] = A[k+1]; A[k+1] = temporal; } } if (flag == 0) break; } }
run
|
edit
|
history
|
help
0
Q1.c
B_141107_TablaMultiplicar
pth_trap.c
1.2 No. of Threads
b=1 c=1
tst2.c
19_1
Welcome1
maximum_template
Day 2 String Manipulation