GCD

GCD of two numbers in C: 

Write a program to find GCD of two numbers

Input:

50

60

Output:

GCD of two numbers is 10.


Program:

#include <stdio.h>  

#include <conio.h>  

int main()  

{     

  int num1,num2;

scanf("%d",&num1);    

scanf("%d",&num2); 

    while (num1 != num2)   

    {  

if (num1 > num2)  

            {  

            num1 = num1 - num2;   

            }  

        else  

            {  

                num2 = num2 - num1;  

                }     

                   }   

    printf("GCD of two numbers is %d.",num2);  

}  


Python:

Write a program to find GCD of two numbers using math.gcd() function.

Input:

50

60

Output:

GCD of two numbers is 10

Program:

import math

m=int(input())

n=int(input())

k=math.gcd(m,n)

print("GCD of two numbers is",k)




Post a Comment

Previous Post Next Post

Contact Form