Question:LCM program in c with multiple numbers
Answer
#include<stdio.h> int lcm(int,int); int main(){ int a,b=1; printf("Enter positive integers. To quit press zero."); while(1){ scanf("%d",&a); if(a<1) break; else if(a>b) b = lcm(a,b); else b = lcm(b,a); } printf("LCM is %d",b); return 0; } int lcm(int a,int b){ int temp = a; while(1){ if(temp % b == 0 && temp % a == 0) break; temp++; } return temp; }
+ Report
LCM program in c with multiple numbers