警告:EXC_Arithmetic(代码= EXC_1386_DIV,子码=为0x0)在C代码
问题描述:
我写了这个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);
,我那个错误。当然有一些错误。 我试图给节点和选定的一个(称为源)分配两个不同的值,以便将其中一个节点(即幸运节点)与我的源进行比较。
你能帮我吗?谢谢。
答
我猜这个问题可能是在这里:
rand()%(5/10)
在这个计算中5/10
等于0,所以这段代码由0
+0
谢谢,anatolyg。 –
分你可能想** **缩短您示例程序([mcve]); **也**可能显示哪一行你得到你的警告/错误。 – anatolyg