answersLogoWhite

0

/*

Assuming that by "a shell program", you mean "a program that is run from a shell", and not "a shell script", then this would fit the bill.

Note that it could be optimized in many ways, such as:

- checking only for prime factors

- only counting as high as the square root of the smaller number

*/

#include <stdio.h>

#include <stdlib.h>

int main( int argc, char *argv[] ){

int val1, val2, n, gcd = 0;

if( argc != 3 ){

fprintf( stderr, "Insufficent arguments. Syntax:\n\tgcf #a #b\n" );

fflush( stderr );

exit( 1 );

}

val1 = atoi( argv[1] );

val2 = atoi( argv[2] );

if( val1 < 2 val2 < 2 ){

printf( "No common factors\n" );

exit( 0 );

}

for( n = 2; n < val1 && n < val2; n++ ) {

if( val1 % n 0 ){

printf( "No common factors\n" );

}else{

printf( "Greatest common factor is %i\n", gcd );

}

return 0;

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Continue Learning about Engineering

Program in 'c' to find the LCM of any given five numbers?

Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.


Flow chart of LCM of two numbers in programming?

To create a flowchart for finding the Least Common Multiple (LCM) of two numbers, start with inputting the two numbers. Then, calculate the Greatest Common Divisor (GCD) of these numbers using the Euclidean algorithm. Next, apply the formula LCM(a, b) = (a * b) / GCD(a, b) to find the LCM. Finally, output the LCM result.


How do you calculate LCM of three numbers by pesudo code?

For this you will need a couple of helper algorithms. The first is the GCD (greatest common divisor) which is expressed as follows:procedure GCD (a, b) isinput: natural numbers a and bwhile ab doif a>blet a be a-belselet b be b-aend ifend whilereturn aThe second algorithm is the LCM (least common multiple) of two numbers:procedure LCM (a, b) isinput: natural numbers a and b return (a*b) / GCD (a, b)Now that you can calculate the GCD and LCM of any two natural numbers, you can calculate the LCM of any three natural numbers as follows:procedure LCM3 (a, b, c) isinput: natural numbers a, b and c return LCM (LCM (a, b), c)Note that the LCM of three numbers first calculates the LCM of two of those numbers (a and b) and then calculates the LCM of that result along with the third number (c). That is, if the three numbers were 8, 9 and 21, the LCM of 8 and 9 is 72 and the LCM of 72 and 21 is 504. Thus the LCM of 8, 9 and 21 is 504.


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


Write a Program in lisp to find remainder?

Here's a simple program in Lisp to find the remainder of two numbers using the mod function: (defun find-remainder (a b) (mod a b)) ;; Example usage: (find-remainder 10 3) ; This will return 1 This function find-remainder takes two arguments, a and b, and returns the remainder of a divided by b.

Related Questions

What is the LCM of 5?

You need at least two numbers to find an LCM.Two or more numbers are needed to find the Lcm


What is th LCM of 4512?

Two or more numbers are needed to find their LCM


What is the LCM of 47814?

Two or more numbers are needed to find their LCM


Program in 'c' to find the LCM of any given five numbers?

Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.


Can you find the LCM of a prime number?

No. You can only find the LCM of at least two numbers, prime or otherwise. The LCM of any two prime numbers is their product.


How do you find two numbers if HCF and LCM are known?

The product of the GCF and the LCM of two numbers is equal to the product of the original two numbers. Multiply the GCF and the LCM. The original two numbers will be another factor pair of that total. Find the factor pair that has that GCF and LCM.


How do you find out the LCM for 36?

You need at least two numbers to find an LCM.


How do you find the LCM for 24?

You need at least two numbers to find an LCM.


How do you find the LCM of 324?

You need at least two numbers to find an LCM.


Find the LCM of 50?

Two or more numbers are needed to find the LCM


What is the LCM of 2 13?

You need at least two numbers to find an LCM.


How do you find 140 by using LCM?

Two or more numbers are needed to find the LCM