top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C Program to find LCM of given numers using Recursion?

+2 votes
1,205 views
C Program to find LCM of given numers using Recursion?
posted Dec 15, 2014 by Chirag Gangdev

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
please no homework!!!

1 Answer

+3 votes
 
Best answer

CODE:

#include<stdio.h>

int lcm(int,int);

int main(){
  int a,b,l;

  printf("Enter any two positive integers ");
  scanf("%d%d",&a,&b);

  if(a>b)
    l = lcm(a,b);
  else
    l = lcm(b,a);

  printf("LCM of two integers is %d",l);
  return 0;
 }

int lcm(int a,int b){
  static int temp = 1;

  if(temp % b == 0 && temp % a == 0)
     return temp;

  temp++;
  lcm(a,b);

  return temp;
 }

Sample output:
Enter any two positive integers 5 2
LCM of two integers is 10

answer Dec 17, 2014 by Shivaranjini
Thanks  Shivaranjini
Similar Questions
+1 vote

Given an array of integers (possibly some of the elements negative), write a C program to find out the *maximum product* possible by adding 'n' consecutive integers in the array, n <= ARRAY_SIZE.

Also give where in the array this sequence of n integers starts.

+1 vote

double the number of vowels in a given string using c programming language
Ex:
Given String="Maven"
Output Required="Maaveen".

...