Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use % operator for float values in c

Tags:

c

math

When I use % operator on float values I get error stating that "invalid operands to binary % (have ‘float’ and ‘double’)".I want to enter the integers value only but the numbers are very large(not in the range of int type)so to avoid the inconvenience I use float.Is there any way to use % operator on such large integer values????

like image 545
Shiv Shakti Avatar asked Sep 21 '11 12:09

Shiv Shakti


People also ask

Can ++ operator be used with float?

For float ++ does not increment by the smallest possble value, but by 1.0. 1.0f has no special meaning (unlike integer 1). It may confuse the reader causing him to think that the variable is int. For float it is not guaranteed that operator++ changes the argument.

How do you #define a float in C?

You can define a variable as a float and assign a value to it in a single declaration. For example: float age = 10.5; In this example, the variable named age would be defined as a float and assigned the value of 10.5.

Can we use operator with float?

% operator cannot be used with floating point numbers in C & C++.

What is the operator for float in C?

In the C Programming Language, the fmod function returns the remainder when x is divided by y.


1 Answers

You can use the fmod function from the standard math library. Its prototype is in the standard header <math.h>.

like image 92
cyco130 Avatar answered Sep 21 '22 20:09

cyco130