#include <stdio.h> #include <stdlib.h> int main() { int a[10] = {0}; int i; int j = 0; int temp; int start = 0; int end = 9; printf("please input the arr:"); while(scanf("%d",&i) != EOF){ a[j++] = i; } while(start <= end){ if(a[start] < 0 && a[end] > 0){ temp = a[start]; a[start] = a[end]; a[end] = temp; start++; end --; }else if(a[start] >= 0){ start++; }else if(a[end] <= 0){ end--; } } for(i = 0; i < 10;i++){ printf("%4d",a[i]); } system("pause"); return 0; }
时间: 2024-10-11 11:01:33