黑马程序员技术交流社区

标题: 乱序数组做法2 [打印本页]

作者: 冬天的章鱼烧    时间: 2015-4-6 23:30
标题: 乱序数组做法2
这个是找下标的思想做的,避免了goto语句,程序更加简洁
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num =0;
    int count =10;
    int index;
    int array[10] ={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
    while (num <10) {
        index = arc4random_uniform(count);
        if (array[index]==-1) {
            array[index]==num++;
        }
    }
    return 0;
}

作者: cysummery    时间: 2015-4-6 23:34
是个好方法,老师也用过




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2