Wednesday, 17 July 2013


//// lcm and gcd /// #include "stdafx.h"#include "stdio.h"#include "conio.h"#include "iostream"using namespace std; int _tmain(int argc, _TCHAR* argv[]){             int n1,n2,lcm,gcd,remainder, numerator,denomerator;       cout<<"enter n1,n2";       cin>>n1>>n2;        if(n1>n2)       {              numerator=n1;              denomerator=n2;       }       else       {              numerator=n2;              denomerator=n1;       }       remainder=n1%n2;       while(remainder!=0)        {              remainder=denomerator;              denomerator=remainder;              remainder=numerator%denomerator;       }              gcd=denomerator;              lcm=(n1*n2)/gcd;              cout<<"gcd="<<gcd;              cout<<"lcm="<<lcm;              getch();}

Reactions:

0 comments :

Post a Comment