# invalid operands to binary %

• 12-03-2005
Mathsniper
invalid operands to binary %
Code:

```#include <stdio.h> #include <stdlib.h> #include <math.h> #define MAXZO 100 void findMinValue(int n, int *zo, int *tail) {         unsigned long i, j, d, zoValue;         for (i = 0; i < MAXZO; i++)                 zo[i] = 0;         *tail = (int)log(n);         zo[*tail] = 1;         do {                 zoValue = n;                 i = 0;                 while (zo[i] == 2) {                         zo[i] = 0;                         zo[++i]++;                 }                 if (*tail > MAXZO) exit(0);                 if (zo[*tail+1] == 1) *tail++;                 for (i = 0; i <= *tail; i++) {                         if (zo[i] == 1) {                                 d = pow(10, (int)log(n)+1) % n;                                 for (j = i; j <= (int)i/log(n); j++)                                         zoValue = (zoValue*d) % n;                         }                         zoValue = (zoValue*pow(10, n-(int)i/log(n))) % n;                 }                 printf("%d\n", zoValue);                 zo[0]++;         } while (zoValue != 0); } int main() {         FILE *fr, *fw;         int n, tail, i;         int zo[MAXZO];         fr = fopen("02.dat", "rt");         fw = fopen("02.out", "wt");         fscanf(fr, "%d", &n);         findMinValue(n, zo, &tail);         for (i = 0; i <= tail; i++)                 fprintf(fw, "%d", zo[i]);         fclose(fr);         fclose(fw);         return 0; }```
I just want to use module operator. But it didn't work.
Code:

```mathsniper:~# gcc -O2 -o 02 02.c -lm 02.c: In function ‘findMinValue’: 02.c:24: error: invalid operands to binary % 02.c:28: error: invalid operands to binary %```
• 12-03-2005
Dave_Sinkula
The % operator does not work with doubles, which pow returns.
• 12-03-2005
grumpy
One example of your problem is this line;
Code:

`d = pow(10, (int)log(n)+1) % n;`
as pow() returns a double. The % operator is only defined for integral types (int, long, unsigned, etc) and has no defined meaning for floating point types.

To get a sort-of equivalent functionality for arguments of type double, look up the function fmod() which is declared in <math.h>
• 12-03-2005
Mathsniper
The problem was solved. Thanks. :)