简体   繁体   中英

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

You should not divide i by 0 you should start your loop with 1

There is a floating point exception because I divided i by 0 so I need to start loop from 1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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