Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Memoria dinamica no funciona ;C
#include <stdio.h> #include <stdlib.h> #include <time.h> void aleatorio (int *, int); void clean (int *, int*); int main(){ int *vector ; int N = 10 ; vector = (int*)malloc(N*sizeof(int)); if (vector == NULL){ printf("no se pudo reservar espacio en la memorioa"); exit(1); } aleatorio(vector,N); clean(vector,&N); } void aleatorio ( int *vector, int N ){ srand(time(NULL)); for (int i = 0 ; i < N ; i++){ *(vector+i) = rand()%4; if ( i+1 < N ) printf("%d, ",*(vector+i)); else printf("%d.",*(vector+i)); } printf("\n"); } void clean(int *vector, int *N){ int j ; for (int i = 0 ; i < *N ; i++){ j = i +1 ; while(j < *N ){ if (*(vector+i) == *(vector+j)){ for (int k = j ; k+1 < *N ; k++){ *(vector+k) = *(vector+k+1); } *N--; } else{ j++; } } } vector = (int*)realloc(vector,*N*sizeof(int)); if (vector == NULL){ printf("No se pudo reservar memoria "); exit(1); } for (int t = 0 ; t < *N ; t++){ printf("%d, ",*(vector+t)); } printf("\n el nuevo valor de N es de %d.",N); }
run
|
edit
|
history
|
help
0
ATM
Array Practice
ques4
array practice
If Statements/Increments V1
Lab 5 HW Spring 2017 v1
20171117_TARTAGLIA
A_141124arrayRepetidos
armstrong number using a while loop
1.5 No. of Processors