answersLogoWhite

0


Best Answer

/* 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;

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program that accepts 15 different numbers and find the LCM and HCM?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you Write a program in 'c' language which accepts int numbers from the users print its reverse number x function which return value?

question clarity


Write a program in Lex to eliminate white space and collect numbers as a token?

write a lex program to delete space from the program


Write a program that accepts as inputs the edges of a graph and then draws the graph using a computer graphics display?

hey i m going to give a program that accepts edges a input and then it draws the graph using a computer graphics display...


How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


Write two ways in which whole numbers and decimal numbers are different?

Write 2 ways in which whole numbers and decimal numbers are different


Shell program for gcd of three given numbers?

write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? check bellow link http://bashscript.blogspot.com/2009/08/gcd-of-more-than-two-numbers.html


How do you write a program in objective c numbers 1-100 prime numbers?

fdsgfhgdfhgdf


Could you Write a program for 8086 microprocessor that displays on the monitor the average of 2 numbers from an array?

How to write a program for mouse in microprocessor?


Write a pseudocode for a program that accepts two integers and substract 5 from the answer?

1. Accept the 2 numbers 2. Add the 2 numbers3. Compare answer with 54. If answer is greater than 5 subtract with 5 else give a error message.


How to write a C program to find largest 2 numbers using pointers?

program to find maximum of two numbers using pointers


Write a program to add two 8 bit numbers in microprocessor 8051?

write it in 8085


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.