
- 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
Program to find GCD of floating point numbers in C++
In this tutorial, we will be discussing a program to find GCD of floating point numbers.
For this we will be provided with two integers. Our task is to find the GCD (Greatest common divisor) of those two provided integers.
Example
#include <bits/stdc++.h> using namespace std; //returning GCD of given numbers double gcd(double a, double b){ if (a < b) return gcd(b, a); if (fabs(b) < 0.001) return a; else return (gcd(b, a - floor(a / b) * b)); } int main(){ double a = 1.20, b = 22.5; cout << gcd(a, b); return 0; }
Output
0.3
- Related Questions & Answers
- C Program to Multiply two Floating Point Numbers?
- Signed floating point numbers
- Java program to multiply given floating point numbers
- Java Program to Multiply Two Floating-Point Numbers
- C program to find GCD of numbers using recursive function
- Java Program to Find GCD of two Numbers
- Program to find GCD or HCF of two numbers in C++
- C++ Program to Find the GCD and LCM of n Numbers
- C program to find GCD of numbers using non-recursive function
- C++ Floating Point Manipulation
- Find GCD of two numbers
- C++ Program to Find GCD
- Floating point comparison in C++
- C++ Program to Find GCD of Two Numbers Using Recursive Euclid Algorithm
- Binary Search for Rational Numbers without using floating point arithmetic in C program
Advertisements