Write a C Program to Compute the LCM and HCF of Two Numbers by using While Statement

LCM and HCF

HCF:
  • HCF Stands For Higest Common Factor.
  • HCF is also Known as GCD (Greatest Common Divisor).
  • HCF of Two Number is defined as the Largest Number that Divides Both Numbers Completely with Remainder Zero.
LCM:
  • LCM Stands For Lowest Common Multiple.
  • LCM of two Numbers Defined as the Smallest Number that is Multiple of both Numbers. 
Statement of C Program: Find The LCM and HCF of Two Numbers :

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

void 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();
}

Output:
 Enter two numbers
 5
 15
 GCD of 5 and 15 = 5
 LCM of 5 and 15 = 15


0 Response to "Write a C Program to Compute the LCM and HCF of Two Numbers by using While Statement"

Post a Comment

Popular Posts

Label

1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag