answersLogoWhite

0

#define SIZE 100

#include <stdio.h>

int hcf_function(int,int);

int lcm_function(int,int);

int main()

{

int array[SIZE],n,i,choice,LCM,hcf;

printf("Enter No of Elements\n");

scanf("%d",&n);

printf("Enter Elements\n");

for(i=0;i<n;i++)

scanf("%d",&array[i]);

do

{

printf("\n\nEnter Choice\n\n1.HCF\n2.LCM\n3.Exit\n");

scanf("%d",&choice);

switch(choice)

{

case 1: hcf=array[0];

for(i=1;i<n;i++)

hcf=hcf_function(hcf,array[i]);

printf("\nHCF = %d",hcf);

break;

case 2: LCM=array[0];

for(i=1;i<n;i++)

LCM=lcm_function(LCM,array[i]);

printf("\nLCM = %d",LCM);

break;

case 3: break;

default:printf("Wrong Choice");

break;

}

}while(choice!=3);

}

/***************************************************************

Function Name : hcf_function

Purpose : to find hcf

Input : two numbers

Return Value : hcf

Return Type : int

****************************************************************/

int hcf_function(int m,int n)

{

int temp,reminder;

if(m<n)

{

temp=m;

m=n;

n=temp;

}

while(1)

{

reminder=m%n;

if(reminder==0)

return n;

else

m=n;

n=reminder;

}

}

/***************************************************************

Function Name : lcm_function

Purpose : to find LCM

Input : two numbers

Return Value : LCM

Return Type : int

****************************************************************/

int lcm_function(int m,int n)

{

int LCM;

LCM=m*n/hcf_function(m,n);

return LCM;

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

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


Define flowchart and draw flowchart for GCD of two numbers?

pictorial representation of a program is called a flowchart


Write a c program to find GCD of two given integers by using both recursive n non recursive functions?

i love u darling


A program to find GCD andLCM of two numbers?

// recursive algorithm to return gcd using Euclid's Algorithm int gcd (int a, int b) { if (a&lt;0) a= -a; if (b&lt;0) b= -b; if (a&lt;b) { int tmp; tmp= a; a= b; b= tmp; } if (b == 0) return a; return gcd (b, a%b); } // LCM using gcd int LCM (int a, int b) { int t; t = a*b; if (t&lt;0) t=-t; return t / gcd (a, b); }


Java program for finding GCD and LCM of two given numbers?

These are the two functions you need: public static int lcm(int i1, int i2) { return (i1*i2/gcd(i1,i2)); } public static int gcd(int i1, int i2) { // using Euclid's algorithm int a=i1, b=i2, temp; while (b!=0) { temp=b; b=a%temp; a=temp; } return a; }


How do you write a C program to find the GCD of two given integers using non recursive functions?

Use the following function: int gcd (int a, int b) { while (b != 0) { a %= b; a ^= b ^= a ^= b; } return a; } Note that a ^= b ^= a ^= b is an efficient method of swapping two values.


How do you find the numbers given the gcd and lcm?

if the gcd and lcm are given and one of the numbers are also given,multiply the gcd and lcm and divide them by the given number


What is pseudo code for GCD of two numbers?

public class GCD { public static void main(String[] args) { //Example how to use this method System.out.println(GCD(15,50)); } //find the greatest common divisor of two numbers public static int GCD(int a, int b){ if (b == 0) return a; return GCD(b, a % b); } } Hope this help to solve you problem.


What is the gcd of any two consecutive even numbers?

The GCD is 2.


What is the assembly language program for GCD of two 16 bit unsigned integers using Intel 8086?

alp for lcm of a no


How do you write a C program to find the GCD and LCM of two numbers using a switch statement?

The following function will return the GCD or LCM of two arguments (x and y) depending on the value of the fct argument (GCD or LCM). enum FUNC {GCD, LCM}; int gcd_or_lcm(FUNC fct, int x, int y) { int result = 0; switch (fct) { case (GCD): result = gcd (x, y); break; case (LCM): result = lcm (x, y); break; } return result; }


The greatest common factor of 114 and 190?

The GCD is 38. You can find it with a calculator, using prime factorization with exponents, or using one of the many on-line GCD calculators.You can also list the factors of both numbers and find the largest one that they have in common.