Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Least common multiple, Assignments of C programming

how to find a lcm of 2 number.

Typology: Assignments

2019/2020

Uploaded on 05/28/2020

m-ganesh-kumar-mahendrakar
m-ganesh-kumar-mahendrakar 🇮🇳

1 document

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#include <stdio.h>
int main()
{
int n1, n2, min;
printf("Enter two positive integers: ");
scanf("%d %d", &n1, &n2);
// maximum number between n1 and n2 is stored in min
min = (n1 > n2) ? n1 : n2;
while (1) {
if (min % n1 == 0 && min % n2 == 0) {
printf("The LCM of %d and %d is %d.", n1, n2, min);
break;
}
++min;
}
return 0;
}
OUTPUT
Enter two positive integers: 15 20
The LCM of 15 and 20 is 60.

Partial preview of the text

Download Least common multiple and more Assignments C programming in PDF only on Docsity!

#include <stdio.h> int main() { int n1, n2, min; printf("Enter two positive integers: "); scanf("%d %d", &n1, &n2);

// maximum number between n1 and n2 is stored in min min = (n1 > n2)? n1 : n2;

while (1) { if (min % n1 == 0 && min % n2 == 0) { printf("The LCM of %d and %d is %d.", n1, n2, min); break; } ++min; } return 0; }

OUTPUT

Enter two positive integers: 15 20 The LCM of 15 and 20 is 60.