錯在哪 求 解!
#include <stdio.h>
int main()
{
? ? int a[10] = {0};
? ? for (int i = 0; i < 10 , i++)
? ? {
? ? ? ? a[i] = arc4random()%50;
? ? ? ? printf ("%d",a[i]);
? ? }
? ? for (int i = 0; i < 10-1 ;i++ )
? ? {
? ? ? ? for(int j = 0;j< 10-1-i ;j++)
? ? ? ? {
? ? ? ? ? ? if(a[j] > a[j+1])
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int temp = a[j];
? ? ? ? ? ? ? ? a[j] = a[j+1];
? ? ? ? ? ? ? ? a[j+1] = temp ;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? printf ("\n");
? ? for (int i = 0;i < 10 ;i++)
? ? {
? ? ? ? printf("%d",a[i]);
? ? }
}
? ? return 0;
}
2015-10-25
在頭文件#include<stdio.h>中不包含隨機(jī)函數(shù)random(),應(yīng)該添加頭文件#include<stdlib.h>.
而且只有在c99標(biāo)準(zhǔn)中才能在for循環(huán)內(nèi)定變量,還有在for循環(huán)內(nèi)應(yīng)用分號隔開表達(dá)式。代碼如下:
2015-10-20
感覺沒錯??!內(nèi)層循環(huán)得到最大值并存儲在a[10-i]中外層循環(huán)九次,得到九個(gè)最大值,最小值在a[0]中,然后打印從小到大的隨機(jī)數(shù)字。
2015-08-27
?你這是冒泡排序吧,為什么要i< 10 -1 ?