/* Program to find LCM/HCF of 15 Nos in C++/ C (replace cin with scanf & cout with printf for c) */
/* Developed by - Kishore Kr. Banerjee - papillon_kish@Yahoo.com */
#include <iostream.h>
#include <conio.h>
main()
{
int num[3],i,j,p,q,tmp,n1,n2,LCM,rem,flag;
clrscr();
for(i=0;i<3;i=i+1)
{
cout<<"Enter No - "<<i+1<<"=";
cin>>num[i];
}
clrscr();
n1=num[0];
p=n1;
for(i=1;i<3;i=i+1)
{
n2=num[i];
/* Finding HCF */
q=n2;
if(p<q)
{
tmp=q;
q=p;
p=tmp;
}
while(p%q!=0)
{
rem=p%q;
q=p;
p=rem;
if(p<q)
{
tmp=q;
q=p;
p=tmp;
}
}
/*finding LCM */
LCM=1;
for(j=1;n1%j==0n2%j==0;j=j+1)
{
if(n1%j==0)
{
n1=n1/j;
flag=1;
}
if(n2%j==0)
{
n2=n2/j;
flag=1;
}
if(flag==1)
{
LCM=LCM*j;
}
}
LCM=LCM*n1*n2;
n1=LCM;
}
cout<<"the LCM ="<<LCM;
cout<<"the hcf ="<<q;
getch();
}
-----
int gcd (int a, int b)
{
. int tmp;
. if (a<0) a= -a;
. if (b<0) b= -b;
. if (a<b) tmp= a, a= b, b= tmp;
. while (b) {
. . tmp= a%b;
. . a= b;
. . b= tmp;
. }
. return a;
}
int gcd_n (int n, const int *vect)
{
. int i, gcdtmp;
. for (i=0, gcdtmp=0; i<n && gcdtmp!=1; ++i)
. . gcdtmp= gcd (gcdtmp, vect[i]);
. return gcdtmp;
}
int LCM (int a, int b)
{
. int d= gcd (a, b);
. if (d==0) return d;
. else return a/d*b;
}
int lcm_n (int n, const int *vect)
{
. int i, lcmtmp;
. for (i=0, lcmtmp=1; i<n; ++i)
. . lcmtmp= LCM (lcmtmp, vect[i]);
. return lcmtmp;
}
Chat with our AI personalities
fdsgfhgdfhgdf
program to find maximum of two numbers using pointers
VBnet program to find the prime numbers between 100 to 200?
By learning how to program on C+.
Rewrite the above program so that the program accepts any value for the radius then recalculate the area of the circle.