answersLogoWhite

0


Best Answer

draw a flow chart to find hcf of two given numbers

User Avatar

Wiki User

โˆ™ 2013-06-11 01:55:09
This answer is:
User Avatar
Study guides

Data Science

โžก๏ธ
See all cards
4.44
โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…
9 Reviews

Add your answer:

Earn +20 pts
Q: How do you draw a flowchart of HCF of two given numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

C program for HCF of two numbers?

#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; }


How do you write a program in C to find the greatest common factor?

Algorithm: to find HCF of two nos a, b 1. Find larger of two and let it l, smaller = s 2. divide l by s and find qotient (q) & remainder(r) 3. if r is 0 then s is the hcf 4. put l=s, s=r and go to step 2 int a, b; int l,s,q,r; if (a>b) {l=a;s=b;} else {l=b;s=a;} do {q= l/s; r=l%s; if (r != 0) {l=s;s=r} } while (r != 0); hcf=s; /* this variable to be output or returned as a function value as per programmer's convenience */


Write a program to find the L.C.M. and HCF of two number using function where numbers are passed as parameter use function with return value?

#include#includevoid main(){int num1 , num2 , lcm , gcd , remainder , numerator , denominator ;clrscr();printf( "Enter two numbers\n");scanf(" %d%d " , &num1 , &num2 );if (num1 > num2){numerator=num1;denominator=num2;}else{numerator = num2 ;denominator = num1 ;}remainder = num1 % num2;while ( remainder != 0){numerator = denominator;denominator = remainder;remainder = numerator % denominator;}gcd = denominator;lcm = (num1 * num2 ) / gcd;printf("GCD of %d and %d =%d\n" , num1, num2, gcd);printf(" LCM of %d and %d= %d\n" , num1, num2, lcm);getch();}


How do you write a program which calculating LCM of 2 numbers in Linux?

Dunno about Linux, but I've written mine in C.It prime factorises the numbers, making a note of the highest power of each prime factor as it goes (in a linked list of malloc()ed structures). Once all the numbers have been factorised, it has a list of all the primes used along with their highest power. The lcm is then the product of the primes raised to their highest power.You are also not limited to the lcm of 2 numbers - you can keep factorising numbers until you run out of them and find the lcm of them all!Whilst you're at it you can add finding their hcf very easily: this time it's the product of the common primes to their lowest power.All that is then needed is the prime factorisation of the numbers.The normal method is:try the first prime (2)If it does not divide the number: set the prime to the next primeTry again from step 2Add one to the power count of this primereplace the number by the number divided by the primeif the number is not 1 go back to step 2Found all primes, stop!Finding the primes by which to divide is not easy on the fly, so you could check 2 specifically and then all odd numbers 3, 5, 7,..., but an improvement is to specifically check 2 and 3 and then check the numbers 6n ± 1 (which may be prime and why are 6n, 6n ± 2 and 6n ± 3 definitely not prime?) which skips every third odd number - this sequence of potential primes (5, 7, 11, 13, 17, 19, ...) can be easily generated.And while you're at it, you could display the prime factorisation you've done.And using that prime factorisation you can list the factors (and factor pairs) for the numbers.Obviously you'll need to sort out how the numbers are input to the program - I decode argv[], but you could use reading from stdin if you prefer.


Write a program in java to find the HCF?

for two positive integers: 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; }

People also asked