2017-04-20 48 views
-2

我寫了這個C代碼:當我分配概率的隨機值的節點或到源警告:EXC_Arithmetic(代碼= EXC_1386_DIV,子碼=爲0x0)在C代碼

printf("The source node %d is \n", source); 
for(i=0; i<V; i++){ //Each node has books+papers*c[t] 
t=0; 
c[t]=0.5; 
books[i]=1000.; 
papers[i]=10; 
items[i][t]=books[i]+papers[i]*c[t]; // Initial items 
} 
for(i=0;i<V;i++){ 
printf("Items[%d][%d] are %.2f\n",i,t, items[i][t]); 
} 

for(i=0;i<V;i++){ 
if(i!=source) { // Assign a random value of probability in the range [0.1,0.4] to the nodes, except the source 
prob_items[i]=rand()%(5/10); 
} else prob_items[i]=rand()%(3/10); // Assign a random value of probability in the range [0.6,0.9] to the source 
} 
do { 
printf("Please randomly select a lucky node\n"); 
lucky=rand()%V; //V are the vertices of the graph 
} while (lucky!=source); 

,我那個錯誤。當然有一些錯誤。 我試圖給節點和選定的一個(稱爲源)分配兩個不同的值,以便將其中一個節點(即幸運節點)與我的源進行比較。

你能幫我嗎?謝謝。

+0

分你可能想** **縮短您示例程序([mcve]); **也**可能顯示哪一行你得到你的警告/錯誤。 – anatolyg

回答

0

這個問題可能是在這裏:

rand()%(5/10) 

在這個計算中5/10等於0,所以這段代碼由0

+0

謝謝,anatolyg。 –

相關問題