Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,927 questions

51,860 answers

573 users

How to use fmod() function to get the floating-point remainder (modulo) of the division x/y in C++

1 Answer

0 votes
using namespace std;

int main()
{
	cout << "fmod(4.3, 2.0) = " << fmod(4.3, 2.0) << endl;
	cout << "fmod(18.5, 4.2) = " << fmod(18.5, 4.2) << endl;
	cout << "fmod(5.1, 3.0) = " << fmod(5.1, 3.0) << endl;
	cout << "fmod(-5.1, 3.0) = " << fmod(-5.1, 3.0) << endl;
	cout << "fmod(5.1, -3.0) = " << fmod(5.1, -3.0) << endl;
	cout << "fmod(-5.1, -3.0) = " << fmod(-5.1, -3.0) << endl;
	cout << "fmod(0.0, 1.0) = " << fmod(0.0, 1.0) << endl;
	cout << "fmod(-0.0, 1.0) = " << fmod(-0.0, 1.0) << endl;
	cout << "fmod(3.1, INFINITY) = " << fmod(3.1, INFINITY) << endl;

	return 0;
}

/*
run:

fmod(4.3, 2.0) = 0.3
fmod(18.5, 4.2) = 1.7
fmod(5.1, 3.0) = 2.1
fmod(-5.1, 3.0) = -2.1
fmod(5.1, -3.0) = 2.1
fmod(-5.1, -3.0) = -2.1
fmod(0.0, 1.0) = 0
fmod(-0.0, 1.0) = -0
fmod(3.1, INFINITY) = 3.1

*/

 



answered Mar 18, 2016 by avibootz
...