

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Modulus of two float or double numbers using C
Here we will see how to get the modulus of two floating or double type data in C. The modulus is basically finding the remainder. For this, we can use the remainder() function in C. The remainder() function is used to compute the floating point remainder of numerator/denominator.
So the remainder(x, y) will be like below.
remainder(x, y) = x – rquote * y
The rquote is the value of x/y. This is rounded towards the nearest integral value. This function takes two arguments of type double, float, long double, and returns the remainder of the same type, that was given as argument. The first argument is numerator, and the second argument is the denominator.
Example
#include <stdio.h> #include <math.h> main() { double x = 14.5, y = 4.1; double res = remainder(x, y); printf("Remainder of %lf/%lf is: %lf\n",x,y, res); x = -34.50; y = 4.0; res = remainder(x, y); printf("Remainder of %lf/%lf is: %lf\n",x,y, res); x = 65.23; y = 0; res = remainder(x, y); printf("Remainder of %lf/%lf is: %lf\n",x,y, res); }
Output
Remainder of 14.500000/4.100000 is: -1.900000 Remainder of -34.500000/4.000000 is: 1.500000 Remainder of 65.230000/0.000000 is: -1.#IND00
- Related Questions & Answers
- Modulus of Negative Numbers in C
- Round float and double numbers in Java
- Float and Double in C
- Checking if a double (or float) is NaN in C++
- Comparison of double and float primitive types in C#
- Difference between float and double in C/C++
- Difference Between Float and Double
- How to compare float and double in C++?
- Find HCF of two numbers without using recursion or Euclidean algorithm in C++
- Comparison of double and float primitive types in Java
- Finding LCM of more than two (or array) numbers without using GCD in C++
- Difference between float and double in Arduino
- C++ Program for GCD of more than two (or array) numbers?
- Program to find GCD or HCF of two numbers in C++
- How do I add two numbers without using ++ or + or any other arithmetic operator in C/C++?
Advertisements