Search
 
SCRIPT & CODE EXAMPLE
 

CPP

gcd function c++

ll gcd(ll a, ll b)
{
    if (b==0)return a;
    return gcd(b, a % b);   
}
Comment

std::gcd

cout << __gcd(17, 97) << endl; //#include <algorithm> 
Comment

c++ finding gcd

// CPP program to illustrate
// undefined behavior of
// gcd function of C++ STL
#include <iostream>
#include <algorithm>
// #include<numeric> for C++17
 
using namespace std;
 
int main()
{
    cout << "gcd(6, 20) = " << __gcd(2.0, 8) << endl; // gcd(2.0,8) for C++17
}
Comment

GCD in cpp

#include <iostream>
using namespace std;

int main() {
  int n1, n2, hcf;
  cout << "Enter two numbers: ";
  cin >> n1 >> n2;

  // swapping variables n1 and n2 if n2 is greater than n1.
  if ( n2 > n1) {   
    int temp = n2;
    n2 = n1;
    n1 = temp;
  }
    
  for (int i = 1; i <=  n2; ++i) {
    if (n1 % i == 0 && n2 % i ==0) {
      hcf = i;
    }
  }

  cout << "HCF = " << hcf;

  return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: virtual function in c++ 
Cpp :: queue in cpp 
Cpp :: && c++ 
Cpp :: what destructor used for in c++ 
Cpp :: binary to decimal online converter 
Cpp :: 83. remove duplicates from sorted list solution in c++ 
Cpp :: problem category codechef solution in c++ 
Cpp :: logisch oder 
Cpp :: Round 1 Confusion codechef solution in c++ 
Cpp :: waiting in a serial as the spool reflect the queue operation. Demonstrate Printer Behavior in context of Queue.Subject to the Scenario implement the Pop and Push Using C++. 
Cpp :: c++ tuple push_back 
Cpp :: Maximum Weight Difference codechef solution c++ 
Cpp :: varint index 
Cpp :: check if a string is a prefix of another c++ 
Cpp :: *= c++ 
Cpp :: c++ fstream read line write ,creat file program 
Cpp :: initalising array c++ 
Cpp :: can i delete a null pointer in c++ 
Cpp :: what c++ library is arccos in 
Cpp :: reading matrix from text file in c++ and adding them and then storing them in oother c++ file 
Cpp :: is variable sized array are not allowed in c++? 
Cpp :: case 1 or 2 c++ 
Cpp :: entering char in int c++ avoid loop 
Cpp :: sleep function i nc++ 
Cpp :: int to string Using boost::lexical_cast 
Cpp :: C++ Array With Empty Members 
Cpp :: C++ Creating a Class Template Object 
Cpp :: how to get a section of a string in c++ 
Cpp :: cosnt cast 
Cpp :: how to show c++ binary files in sublime text 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =