
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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
",x,y, res); x = -34.50; y = 4.0; res = remainder(x, y); printf("Remainder of %lf/%lf is: %lf
",x,y, res); x = 65.23; y = 0; res = remainder(x, y); printf("Remainder of %lf/%lf is: %lf
",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 Articles
- Round float and double numbers in Java
- Modulus of Negative Numbers in C
- Checking if a double (or float) is NaN in C++
- Float and Double in C
- Difference between float and double in C/C++
- Comparison of double and float primitive types in C#
- How to compare float and double in C++?
- Difference Between Float and Double
- Find HCF of two numbers without using recursion or Euclidean algorithm in C++
- How to add float numbers using JavaScript?
- Finding LCM of more than two (or array) numbers without using GCD in C++
- Difference between float and double in Arduino
- How do I add two numbers without using ++ or + or any other arithmetic operator in C/C++?
- C++ Program to find size of int, float, double and char in Your System
- Program to find GCD or HCF of two numbers using Middle School Procedure in C++

Advertisements