Tuesday, February 10, 2015

HCF and LCM

Description : HCF is also known as greatest common divisor(GCD) or greatest common factor(gcf).
#include <iostream.h> int main() { int a, b, x, y, t, gcd, lcm; cout<<"Enter two integers\n"; cin>>x>>y; a = x; b = y; while (b != 0) { t = b; b = a % b; a = t; } gcd = a; lcm = (x*y)/gcd; cout<<"Greatest common divisor of "<<x<<"and"<<y<<" = "<<<gcd<<"\n"; cout<<"Greatest common divisor of "<<x<<"and"<<y<<" = "<<lcm<<"\n"; return 0; }

Share

& Comment

0 comments:

Post a Comment

 

Copyright © 2015 Code Fervor™ is a registered trademark.

Designed by Templateism By Naman Kumar