views:

108

answers:

2

i have following code

#include <iostream>
#include<exception>
#include <cstdlib>
int main(){
     for (int i=0;i<100;i++){
        std::cout<<i<<" ";
        if (i %5==0){
         abort();
        }

     }




         return 0;


}

but it only writes 0 and says that abort was called why?i think it should ouput 0 1 2 3 4 and than exit program yes?

+4  A: 

Think of % as "remainder after division." 0 / 5 equals 0 with a remainder of 0.

Jacob
yes i have corrected thanks
+1  A: 

when i is 0, 0 % 5 equals 0

Inverse