開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
DEV C++
問題(Question):
我想要隨機產生一百個介於1~100的亂數
印出產生的100個亂數
然後在底下印出平均值
執行時印出亂數後還沒印出平均值就停止程式
我拿去問教授他說看起來沒有錯
換一台電腦跑看看就可以了
可是我試了三台電腦還是不行
餵入的資料(Input):
無
預期的正確結果(Expected Output):
隨機產生一百個介於1~100的亂數並取算出平均值
錯誤結果(Wrong Output):
雖然編譯的過,但是開始執行後就出現程式已經停止運作,然後發現底下也出現一行警告
訊息,上網查了一下好像是指標問題,可是我沒有用指標啊@@
[Warning] passing arg 1 of 'Average' makes pointer from integer without a cast.
程式碼(Code):(請善用置底文網頁, 記得排版)
網站: http://ideone.com/wkvLhx
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUM 100
float Average(int []);
int main()
{
int n[NUM], i;
srand(time(NULL));
for(i = 0; i<NUM; i++) {
n[i] = rand()%100 + 1 ;
printf("%d%c",n[i],(i%10==9)?'\n':'\t');
}
printf("