输入一个数组 使得所有负的在正的前面

#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;
    }

 

posted @ 2015-05-03 18:00  码农@163  阅读(184)  评论(0编辑  收藏  举报