I'm trying to use a for loop to iterate over the elements of an integer array and find out if a particular element in that array is equal to some other integer.
Here's what I've got, and it doesn't seem to work:
int squaresArray[1000];
int numberOfSquares = 1000;
int i = 0;
for (i; i<=numberOfSquares; i++)
{
squaresArray[i] = i*i;
if (number == squaresArray[i]){
printf("%d is a perfect square\n", number);}
break;
}
According to what I know about for loops this should work, but it prints nothing even when the number should be equal to some element of the array.