Friday, November 29, 2013


/* C program to find LCM of two positive integers entered by user */ 
#include<stdio.h> 
int main() 

int n1,n2,temp1,temp2; 
printf("Enter two positive integers: "); 
scanf("%d %d",&n1,&n2);
 temp1=n1;
 temp2=n2;
   while(temp1!=temp2)
    { 
      if(temp1>temp2)
         temp1-=temp2; 
      else 
        temp2-=temp1;
    }
 printf("LCM of two numbers %d and %d is %d", n1, n2, (n1*n2)/temp1);
return 0;
}

Output:
Enter two positive numbers: 15 9 
LCM of two numbers 15 and 9 is 45

No comments :

Post a Comment