
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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 Articles
- C Program to Multiply two Floating Point Numbers?
- Java program to multiply given floating point numbers
- Java Program to Multiply Two Floating-Point Numbers
- Swift Program to Multiply Two Floating-Point Numbers
- Haskell program to multiply two floating point numbers
- Kotlin Program to Multiply Two Floating-Point Numbers
- Program to find GCD or HCF of two numbers in C++
- C program to find GCD of numbers using recursive function
- Java Program to Find GCD of two Numbers
- Swift Program to Find GCD of two Numbers
- Kotlin Program to Find GCD of two Numbers
- C++ Program to Find the GCD and LCM of n Numbers
- C program to find GCD of numbers using non-recursive function
- Golang Program that switch on floating-point numbers
- Signed floating point numbers

Advertisements