C program to find LCM and HCF of two numbers
#include<stdio.h>#include<conio.h>
void main(){ int a,b,hcf,lcm,max,min,r; clrscr(); printf("Enter two numbers:"); scanf("%d%d",&a,&b);
if(a>b) { max=a; min=b; } else if(b>a) { max=b; min=a; }
if(a==b) hcf=a; else { do { r=max%min; max=min; min=r; }while(r!=0); hcf=max; }
lcm=(a*b)/hcf; printf("
LCM=%d
HCF=%d",lcm,hcf); getch();}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.