Why am I getting 'Floating point exception: 8'

六月ゝ 毕业季﹏ 提交于 2019-11-29 15:41:42

Well, it's really hard to understand what your code is doing. But still

for(i=1;i<100;i++)
    for(j=2;j<100;j++)
        if((nums[i] % nums[j]) == 0)
        {
            nums[j] = 0;
        }

After this, many values of nums will be 0.(You can print and check)

So, Later when you are doing

for(z=0;z<100;z++)
{  
  for(k=i;k<100;k++)
   for(l = (k+2);l < 100;l++)
     if((nums[k] % nums[l]) == 0) //Part where division by 0 occurs
       nums[k] = 0;
}

There will be a division by 0, which is giving the floating point exception

Edited

Infact, there will be a floating point exception in the first two for loops only.. When i=2 and j=2, nums[2] will get updated to value 0. Then later when for i=4 and j=2. There will be a division by 0, because num[2] is already 0, thus causing the floating point exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!