為什麼這篇c陣列大小限制鄉民發文收入到精華區:因為在c陣列大小限制這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!作者gw119 (我想出去玩啦)看板C_and_CPP標題[問題] 陣列大小有上限嗎時間Tue Ma...
#include<iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <string.h>
#include <fstream>
#include <math.h>
using std::cout;
using std::endl;
using namespace std;
double unif(double &seed);
double norm(double mean, double var);
int main(void)
{
double mean = 0;
double SNR =10.0;
double var =1/pow(10 , SNR/10);
double w[1000][100]={0};
double err = 0;
double total = 10000000;
int t[1000][100] = {0};
double r[1000][100] = {0};
for(int j=0 ; j<100 ;j++)
{
for(int i=0 ; i<1000; i++)
{
t[i][j] = -1;
w[i][j] = norm(mean,var);
r[i][j] = t[i][j]+w[i][j];
if(r[i][j]>=0)
{
err+=1;
}
}
}
ofstream fop("re.txt");
fop<<(err/total);
cout<<"解碼結束"<<endl;
fop.close();
system("pause");
}//////end
double unif(double &seed)
{
double a1=3972.0,a2=4094.0;
double m=2147483647.0;
double seed1,seed2;
seed1 = a1 * seed ;
seed2 = a2 * seed ;
/* control seed < 10^10 */
seed1 = seed1 - (long)(seed1/m) * m ;
seed2 = seed2 - (long)(seed2/m) * m ;
seed = seed1 * 100000.0 + seed2;
seed = seed - (long)(seed/m)*m;
if((seed/m)<0){
return(-1*seed/m);}
else
return(seed/m);
}
double norm(double mean, double var)
{
double sz=0.0,v1,v2,sigma,ans;
double seed1,seed2;
sigma=sqrt(var);
seed1=rand()+clock()*123;
v1=unif(seed1);
seed2=fabs(clock()*1236*var+rand()-seed1);
v2=unif(seed2);
sz=cos(2.*3.14*v1)*sqrt(-2.*log(v2));
ans=sz*sigma+mean;
return(ans);
}
我想請教的問題是當我把w[1000][100]裡面的1000改成10000然後其它像
t[][]還有r[][]跟i都改成對應的10000後,程式就出現overflow的訊息
這是因為我設定超過陣列的上限嗎,因為像1000就可以執行但改成
10000就不能,請問板上的高手這是甚麼問題呢,感謝^^
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.122.235