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.

40,039 questions

52,004 answers

573 users

How to calculate ratio in C++

1 Answer

0 votes
#include <iostream>
#include <ratio>


int main()
{
	typedef std::ratio<5, 3> FiveThirds1;
	std::cout << FiveThirds1::num << "/" << FiveThirds1::den << std::endl;

	typedef std::ratio<25, 15> FiveThirds2;
	std::cout << FiveThirds2::num << "/" << FiveThirds2::den << std::endl;

	std::ratio<13, 13> one;
	std::cout << one.num << "/" << one.den << std::endl;

	std::ratio<0> zero;
	std::cout << zero.num << "/" << zero.den << std::endl;

	typedef std::ratio<9, -4> NegPos1;
	std::cout << NegPos1::num << "/" << NegPos1::den << std::endl;
	
	typedef std::ratio<9, -3> NegPos2;
	std::cout << NegPos2::num << "/" << NegPos2::den << std::endl;

	return 0;
}

/*
run:

5/3
5/3
1/1
0/1
-9/4
-3/1

*/

 



answered Nov 26, 2017 by avibootz
...