Created
May 21, 2018 12:33
-
-
Save frzleaf/e2beb915685fc2355824aac7a3cc3aad to your computer and use it in GitHub Desktop.
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> | |
int *taomang(soluong){ | |
int i = 0; | |
int *mang = (int *) malloc(soluong * sizeof(int)); | |
for ( ; i < soluong; ++i){ | |
scanf("%d", (mang + i)); | |
} | |
return mang; | |
} | |
int inmang(int *mang, int soluong){ | |
int i = 0; | |
for ( ; i < soluong; ++i){ | |
printf("%d\n", *(mang + i)); | |
} | |
} | |
int *amdauduongcuoi(int *mang, int soluong){ | |
int dau = 0; | |
int cuoi = soluong - 1; | |
int i = 0; | |
for ( ; dau < cuoi || i < soluong ; ++i ){ | |
if(*(mang + i) < 0 ){ | |
int tmp = *(mang + i); | |
*(mang + i) = *(mang + dau); | |
*(mang + dau) = tmp; | |
dau++; | |
} else if ( *(mang + i) > 0){ | |
int tmp = *(mang + i); | |
*(mang + i) = *(mang + cuoi); | |
*(mang + cuoi) = tmp; | |
cuoi --; | |
} | |
} | |
return mang; | |
} | |
int main(){ | |
printf("Nhap so phan tu, sau do nhap mang: \n"); | |
int soluong; | |
scanf("%d", &soluong); | |
int *mang = taomang(soluong); | |
amdauduongcuoi(mang, soluong); | |
inmang(mang, soluong); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment