I have made sure that in the statement i%a[i] == 0
, that i
and a[i]
are between 1 and 100. But still, I get this error message!
#include <stdio.h>
int main()
{
int n, m, x = 0, count = 0;
scanf("%d %d", &n, &m);
int a[n], b[m];
for(int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
for(int i = 0; i < m; i++)
{
scanf("%d", &b[i]);
}
for(int i = 1; i <= 100; i++)
{
if(i % a[i] == 0)
{
x++;
}
else if(b[i] % i == 0)
{
x++;
}
if(x == 2)
{
count++;
}
else
{
continue;
}
x = 0;
}
printf("%d", count);
return 0;
}
Error Message:
Program terminated with signal SIGFPE, Arithmetic exception.
#0 0x0000000000401113 in main () at Solution.c:23
23 if(i%a[i]==0){