I started learning C++ recently, and thought I would test my mettle with Project Euler problems. I solved the first two, but I am stuck on the third. It is compiling correctly without any errors, but it is crashing as soon as it is executed. I tried removing the nested for loops to isolate the problem, and it still crashed.
#include<iostream>
#include<math.h>
int main()
{
float quot;
int num = 0;
int array[100];
float next;
for(int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
if((i % j) == 0)
{
quot=j/i;
num=num+1;
}
if (num=2)
{
array[i]=i;
}
}
}
for (int i = 0; i < 100; i++)
{
if((13195 % i) == 0)
{
std::cout << i;
}
}
}
In if((i%j)==0)
if i
and j
are zero, your next line is dividing i and j. This is division by zero.
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.