C program to find the GCD and LCM of two integers output the results along with the given integers. Use Euclids’ algorithm

by Nideesh C on April 12, 2011 · 0 comments

in C Programming




/* C program to find the GCD and LCM of two integers output the results along with the given integers. Use Euclid’s’ algorithm */

#include <stdio.h>
#include <conio.h>

void main()
{
int  num1, num2, gcd, lcm, 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);
}        /* End of main() */
/*————————
Output
RUN 1
Enter two numbers
5
15
GCD of 5 and 15 = 5
LCM of 5 and 15 = 15
——————————*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Sample – Program to enter an integer and output it in the reversed form.
  2. C program to find and output all the roots of a quadratic equation, for non-zero coefficients.
  3. C program to simulate a simple calculator to perform arithmetic operations like addition, subtraction,multiplication and division only on integers
  4. Sample – Program to enter two integers and print the quotient and remainder.
  5. Write a C program to find the sum of ‘N’ natural numbers

Leave a Comment

Previous post:

Next post: