Cool
Cool

Reputation: 27

Invalid operands to binary (have float and float)

#include <stdio.h>
#include <math.h>
int main()
{
    float n,f;
    printf("n too:");
    scanf("%f",&n);
    f=sqrt(n);
    f=n%f;
    printf("%f",f);
    return(0);
}

It iss my code. But i get this "Invalid operands to binary (have float and float)" error in 9th line.

How to solve this ?

Upvotes: 0

Views: 1175

Answers (1)

haccks
haccks

Reputation: 106012

Operands of % must be of integer type. You should use the library function fmod.

C11: 7.12.10.1 The fmod functions

Synopsis

#include <math.h>
double fmod(double x, double y);
float fmodf(float x, float y);
long double fmodl(long double x, long double y);

Description

The fmod functions compute the floating-point remainder of x/y.

Upvotes: 4

Related Questions