简体   繁体   English

简单c++代码浮点异常错误

[英]Floating point exception error in simple c++ code

#include <iostream>
using namespace std;

int main() {
    // your code goes here
    int t,x,y,z,set,i,check=0;
    cin>>t;
    while(t--)
    {
        cin>>x>>y>>z;
        
        check=z-(x+y);
       
      for(i=0;i<10;i++){
            if(check%i==0)
            {
                set=i;
            }
           // i++;
        }
        cout<<set<<endl;
    }
        
    return 0;
}

While I run this code then I get run time error like当我运行此代码时,出现运行时错误,例如

FLoating point exception浮点异常

and from next input it gives error like:从下一个输入开始,它会给出如下错误:

dash: 2: 4:not found破折号:2:4:未找到

You should not divide i by 0 you should start your loop with 1你不应该将 i 除以 0 你应该从 1 开始你的循环

There is a floating point exception because I divided i by 0 so I need to start loop from 1.有一个浮点异常,因为我将 i 除以 0,所以我需要从 1 开始循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM