#include<iostream>
#include<math.h>
#include<time.h>
#include<stdlib.h>
#include<fstream>
#include<iomanip>
using namespace std;
const int tempnx=11,tempny=11;
unsigned long I = 1;
const unsigned long a = 16807; //亂數 乘法器采用16807
unsigned long m = pow(2, 31) - 1; //線性同乘余法初始值設定
double z, num; //所求的亂數
double random() //線性同乘余法演算法亂數產生函式,亂數范圍為0.0000~1.0000
{
if (I == m)
I = m - 1;
I = (a*I) % m;
z = I;
num = z / m;
return num;
}
void main(void)
{
int i=0,j=0,l=0;
double randnum;
int walkn=0,walki=0, stepi=0,stepj=0,step4=0;
double temp[tempnx][tempny];
int tempv[tempnx][tempny];
for (i=0;i<tempnx;i++)
{ for (j=0;j<tempny;j++)
{
temp[i][j]=0.0;
tempv[i][j]=0; } } // 初值
j=0; // 邊界
for (i=0;i<tempnx;i++)
{
tempv[i][j]=1; }
j=tempny-1;
for (i=0;i<tempnx;i++)
{
tempv[i][j]=1; }
i=0;
for (j=0;j<tempny;j++)
{
temp[i][j]=1.0;
tempv[i][j]=1; }
i=tempnx-1;
for (j=0;j<tempny;j++)
{
temp[i][j]=1.0;
tempv[i][j]=1; }
cout<<setw(15)<<"walkn= "<< '\n';
cin>>walkn;
for (i=1;i<tempnx-1;i++)
{
for (j=1;j<tempny-1;j++)
{
for (walki=0;walki<walkn;walki++)
{
stepi=i;
stepj=j;
while (tempv[stepi][stepj] == 0)
{
randnum=random();
step4=int(randnum*4)+1;
if (step4 == 1)
stepi=stepi+1;
else if (step4 == 2)
stepi=stepi-1;
else if (step4 == 3)
stepj=stepj+1;
else if (step4 == 4)
stepj=stepj-1;
}
temp[i][j]=temp[i][j]+temp[stepi][stepj];
}
temp[i][j]=temp[i][j]/float(walkn);
}
}
fprintf*****;}
這個程式 除錯運行后,出現一個錯誤
error C2059: syntax error : ';'
找不到問題所在qaq
希望有老師朋友同學能幫忙解決一下
uj5u.com熱心網友回復:
qaq 麻煩大家了 自己非計算機專業學生 除錯代碼 有點不熟悉了
uj5u.com熱心網友回復:
最后一行fprintf是你寫的嗎?uj5u.com熱心網友回復:
老師pdf源程式有的
uj5u.com熱心網友回復:
注釋過好像沒問題
uj5u.com熱心網友回復:
可以把錯誤完整資訊發出來uj5u.com熱心網友回復:
就這一個錯誤 qaq
uj5u.com熱心網友回復:
最后一行去掉呀,就應該行了uj5u.com熱心網友回復:
試過了 不行 看其他示例好像是陣列有問題
uj5u.com熱心網友回復:
所以你把完整的錯誤截圖發出來阿uj5u.com熱心網友回復:
#include<iostream>#include<math.h>
#include<time.h>
#include<stdlib.h>
#include<fstream>
#include<iomanip>
using namespace std;
const int tempnx=11,tempny=11;
unsigned long I = 1;
const unsigned long a = 16807; //亂數 乘法器采用16807
unsigned long m = pow(2.0, 31) - 1; //線性同乘余法初始值設定
double z, num; //所求的亂數
double random() //線性同乘余法演算法亂數產生函式,亂數范圍為0.0000~1.0000
{
if (I == m)
I = m - 1;
I = (a*I) % m;
z = I;
num = z / m;
return num;
}
void main(void)
{
int i=0,j=0,l=0;
double randnum;
int walkn=0,walki=0, stepi=0,stepj=0,step4=0;
double temp[tempnx][tempny];
int tempv[tempnx][tempny];
for (i=0;i<tempnx;i++)
{ for (j=0;j<tempny;j++)
{
temp[i][j]=0.0;
tempv[i][j]=0; } } // 初值
j=0; // 邊界
for (i=0;i<tempnx;i++)
{
tempv[i][j]=1; }
j=tempny-1;
for (i=0;i<tempnx;i++)
{
tempv[i][j]=1; }
i=0;
for (j=0;j<tempny;j++)
{
temp[i][j]=1.0;
tempv[i][j]=1; }
i=tempnx-1;
for (j=0;j<tempny;j++)
{
temp[i][j]=1.0;
tempv[i][j]=1; }
cout<<setw(15)<<"walkn= "<< '\n';
cin>>walkn;
for (i=1;i<tempnx-1;i++)
{
for (j=1;j<tempny-1;j++)
{
for (walki=0;walki<walkn;walki++)
{
stepi=i;
stepj=j;
while (tempv[stepi][stepj] == 0)
{
randnum=random();
step4=int(randnum*4)+1;
if (step4 == 1)
stepi=stepi+1;
else if (step4 == 2)
stepi=stepi-1;
else if (step4 == 3)
stepj=stepj+1;
else if (step4 == 4)
stepj=stepj-1;
}
temp[i][j]=temp[i][j]+temp[stepi][stepj];
}
temp[i][j]=temp[i][j]/float(walkn);
}
}
}
uj5u.com熱心網友回復:
把這個拷貝過去,就可以了uj5u.com熱心網友回復:
?? 我寫完作業看一下 謝謝老哥
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/64611.html
標籤:C++ 語言
