Search
 
SCRIPT & CODE EXAMPLE
 

CPP

gcd in c program

#include <stdio.h>
int main()
{
    int n1, n2, i, gcd;

    printf("Enter two integers: ");
    scanf("%d %d", &n1, &n2);

    for(i=1; i <= n1 && i <= n2; ++i)
    {
        // Checks if i is factor of both integers
        if(n1%i==0 && n2%i==0)
            gcd = i;
    }

    printf("G.C.D of %d and %d is %d", n1, n2, gcd);

    return 0;
}
Comment

gcd = 1

import java.util.Scanner;
public class   Euclid {
    static public void main(String[] argh){
        System.out.print("Enter two numbers: ");
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int TEMP = 0 ;
        int GCD = 0;
        int max = a>b?a:b;
        int min = a<b?a:b;
        while(min!=0){
            TEMP=(max%min);
            GCD = min ;
            min = TEMP;
        }
        System.out.print("("+GCD+")");
    }
}

Comment

GCD(x, yz)

long long g = gcd(x, y);
return g * gcd(x / g, z);
Comment

PREVIOUS NEXT
Code Example
Cpp :: hpp files 
Cpp :: check if a variable is tring c++ 
Cpp :: c++ comments 
Cpp :: what is vector capacity in c++ 
Cpp :: how to refresh multiple command lines in C++ stream 
Cpp :: how to change the default camera speed values opengl 
Cpp :: xor linked list 
Cpp :: find number of 1s in a binary cv::mat image 
Cpp :: Arduino C++ servomotor random moving 
Cpp :: print the elements of the array without using the [] notation in c++ 
Cpp :: c++ copy with transform 
Cpp :: what are manipulators in c++ 
Cpp :: leetcode 36 c++ 
Cpp :: 378. Kth Smallest Element in a Sorted Matrix using binary search 
Cpp :: catalan numbers c++ 
Cpp :: https://www.google 
Cpp :: codeform 
Cpp :: columntransformer onehotencoder 
Cpp :: sprintf add two xeroes for a float number 
Cpp :: show mouse c++ 
Cpp :: csv 
Cpp :: nested loop c++ program example 
Cpp :: dijkstra algorithm in c++ geeksforgeeks 
Cpp :: how to calculate the sum of primary diagonal matrix and secondary diagonal matrix using c++ 
Cpp :: Stack Modified 
Cpp :: c++ shift array to the right 
Cpp :: how to include a library in arduino 
Cpp :: how to make an enum in c++ 
Cpp :: cpp 
C :: install kubernetes kubectl on mac 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =