-1

I am trying to create a program in C to find the k'th continuing not free square numbers.

For example if k=3 it will print 48,49,50.

However I'm constantly hitting this error:

[Error] invalid operands of types 'double' and 'double' to binary 'operator%'

The error is in this line: if (x % pow(j, 2)=0)

Here is my code:

#include <stdio.h>
#include <math.h>
#define K 6

int main()
{
    int i,j,x;
    while(i!=0)
    {
        for (x=4; x<=1000000000; x++)
        for(j=2; j<=113; j++)
        {
            if (x % pow(j, 2)=0)
            {
                printf("%d",x);
            }
        }
    }
}
Calico
  • 426
  • 1
  • 4
  • 17
charis
  • 1
  • the idea behind (x % pow(j, 2)=0) is that any not free square number(y) has a divisible number(for example, x) which can be created by a pow(x, 2) and that pow number can be multiplied with a (z) number to make y – charis Oct 28 '17 at 12:41
  • Please explain clearer what you are doing from a mathematical point of view. – Dirk Horsten Oct 28 '17 at 12:42
  • for example both 48,49,50 => 48=(4x4)x3 , 49=(7x7)x1 , 50=(5x5)x2, and please don't forget that 48,49,50 are 3 continuing not free square numbers , that kind of solution i want to make my program finds – charis Oct 28 '17 at 12:45
  • if you Dirk Horsten don't understand my comments its ok , but please focus to help me with the error "[Error] invalid operands of types 'double' and 'double' to binary 'operator%' " in the line of code "if (x % pow(j, 2)=0)" – charis Oct 28 '17 at 12:52
  • 1
    This is no chat box in which old conversations are forgotten, charis. We are building a knowledge base for future reference. Therefore, we must improve the questions even if we understand them. – Dirk Horsten Oct 28 '17 at 12:58
  • The error message is very precise and unambiguous. What exactly is unclear about it? – n. m. could be an AI Oct 30 '17 at 07:26

1 Answers1

1
  • A single equality sign in C is assigning the value form the right to the variable on the left. For comparison, use a dounle equality sign.
  • As soon as you have a bug you do not understand, instead of relying on the precedence of operators, add brackets
  • The % operator works on integers and pow returns a double, so you have to cast your result to an integer

Try replacing if (x % pow(j, 2)=0) by if ((x % (int) pow(j, 2))==0).

Dirk Horsten
  • 3,753
  • 4
  • 20
  • 37
  • 1
    your code did not do anythink.I tested it. Its very complicated for using pow because it takes int numbers and pull out double so that's the why I use j*j instead of pow(j, 2) – charis Oct 28 '17 at 15:07
  • but the problem with pow is still unfixed – charis Oct 28 '17 at 15:08
  • the error is [Error] invalid operands of types 'int' and 'double' to binary 'operator%' – charis Oct 28 '17 at 15:13