Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ program to find gcd of 3 numbers

#include<stdio.h>
int main() {    
  int a,b,c,hcf,st;
  printf("Enter three numbers : ");
  scanf("%d,%d,%d", &a,&b,&c);
  st=a<b?(a<c?a:c):(b<c?b:c);
  for (hcf=st;hcf>=1;hcf--) 	{  	  
    if (a%hcf==0 && b%hcf==0 && c%hcf==0)
      break;
  }
  printf("%d",hcf); return 0;
}
Comment

Program to find GCD or HCF of two numbers c++

// C++ program to find GCD of two numbers
#include <bits/stdc++.h>
using namespace std;
 
int static dp[1001][1001];
 
// Function to return gcd of a and b
int gcd(int a, int b)
{
    // Everything divides 0
    if (a == 0)
        return b;
    if (b == 0)
        return a;
 
    // base case
    if (a == b)
        return a;
     
    // if a value is already
    // present in dp
    if(dp[a][b] != -1)
        return dp[a][b];
 
    // a is greater
    if (a > b)
        dp[a][b] = gcd(a-b, b);
     
    // b is greater
    else
        dp[a][b] = gcd(a, b-a);
     
    // return dp
    return dp[a][b];
}
 
// Driver program to test above function
int main()
{
    int a = 98, b = 56;
    memset(dp, -1, sizeof(dp));
    cout<<"GCD of "<<a<<" and "<<b<<" is "<<gcd(a, b);
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Temparory Email Id 
Cpp :: order 2d array in c++ 
Cpp :: c++ linked list 
Cpp :: count c++ 
Cpp :: c++ create function pointer 
Cpp :: and c++ 
Cpp :: c++ class constructor variable arguments 
Cpp :: 1. Two Sum 
Cpp :: C++ Vector Operation Change Elements 
Cpp :: pointer to pointer c++ 
Cpp :: initialisation of a c++ variable 
Cpp :: max and min function in c++ 
Cpp :: unordered_map in c++ 
Cpp :: c++ bit shift wrap 
Cpp :: bit masking tricks 
Cpp :: expresiones regulares español 
Cpp :: prefix using stack 
Cpp :: how to scan vector in c++ 
Cpp :: use textchanged qt cpp 
Cpp :: point in polygon 
Cpp :: cpp how to add collisions to boxes 
Cpp :: c++ restrict template types 
Cpp :: Types of Triangles Based on Angles in c++ 
Cpp :: softwareegg.courses4u 
Cpp :: c++ program that put a space in between characters 
Cpp :: how to print out a two dimensional array in c++ 
Cpp :: Edmonds-Karp algorithm C++ 
Cpp :: Imports the elements in the array c++ 
Cpp :: Runtime error(Exit status:153(File size limit exceeded)) c++ 
Cpp :: 28+152+28+38+114 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =