Thursday, December 15, 2011

C Program to find Hcf and Lcm Of numbers

int hcf(int n, int m) 

 
    int temp; 
    while( m > 0) 

        temp = n; 
        n = m; 
        m = temp % m; 
    } 
    return n; 

 
int lcm(int n, int m) { 
    int product = n*m; 
    int hcf = hcf(n,m); 
    int lcm = product/hcf; 
    return lcm; 

int main() 

    int n, m; 
    scanf("%d%d",&n,&m); 
    printf("%d\n",lcm(n,m)); 
    return 0; 
}

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. thanx i ws a bit confused..finally executed dis algo at raptor tool :)

    ReplyDelete