码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-05-03 18:53:21      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

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

 

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

标签:

原文地址:http://www.cnblogs.com/joyclub/p/4474363.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!