Question

In: Computer Science

USE R 2520 is the smallest number that can be divided by each of the numbers...

USE R

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. Now you need to create a function to find the smallest positive number that is evenly divisible by two numbers you input into the function. (For example, your input is 6 and 9, you need to find the smallest number which can be divided by 6, 7, 8 and 9)

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

=

# Find the GCD of the numbers x and y.

gcd = function (x, y) ifelse(x == 0, y, gcd(y %% x, x))

# Find the LCM here

lcm = function (x, y) x*y/gcd(x,y)

# Use the reduce function to do the process

# Pass the arguments start:stop to the function

print(Reduce(lcm, 1:10))

print(Reduce(lcm, 1:20))

print(Reduce(lcm, 6:9))

print(Reduce(lcm, 3:7))

=================


Related Solutions

Please use minimum cost rule to solve this problem. When the smallest numbers in a tie...
Please use minimum cost rule to solve this problem. When the smallest numbers in a tie in the same column?How to determine which one should be picked? And It they are in the same row and the demands are also the same, how to pick? Thank you Transportation Tableau Steel1 Steel 2 Steel 3 Dummy Plant 1 60 40 28 0 120 Plant 2 50 30 30 0 150 Plant 3 20 20 20 0 160 100 100 100 130...
Use C Programming - Given an array of integers and a number K, find the smallest...
Use C Programming - Given an array of integers and a number K, find the smallest element in array greater than or equal to K. If such element exists in the array, display it otherwise display "-1". Example: Input:     8     1 3 4 7 8 9 9 10     5     where: First line represents the number of elements in the array. Second line represents the elements in the array. Third line represents the value of K. Output:     7 Explanation:...
A number is prime if it can be divided exactly only by 1 and itself. Here...
A number is prime if it can be divided exactly only by 1 and itself. Here is an algorithm for checking if an input number is prime: function out = isprime(m)             for j:=2 to m-1             if mod(m,j) ==0 then             return “input is not a prime”             endif             endfor             return ”input is a prime” Let n denote the size of the input m, i.e. the number of bits in the binary expression for m. What is...
23 The relative frequency is the frequency in each class divided by the total number of...
23 The relative frequency is the frequency in each class divided by the total number of observations. A true B false 24, The scatter plot can visually show the relationship between two variables. A false B True 25 Ratio measurement scales indicate both rank and distance from a natural zero. A true B false 26 A time series diagram is a bar chart that displays the frequency of defect causes and is used to separate the "vital few" from the...
Let k ≥ 2. Use that R (the real numbers) is complete to show R^k is...
Let k ≥ 2. Use that R (the real numbers) is complete to show R^k is complete.
Use R to do each of the following. Use R code instructions that are as general...
Use R to do each of the following. Use R code instructions that are as general as possible, and also as efficient as possible. Use the Quick-R website for help on finding commands. 1. The following is a random sample of CT scores selected from 32 Miami students. 28, 27, 29, 27, 29, 31, 32, 30, 34, 30, 27, 25, 30, 32, 35, 32 23, 26, 27, 33, 33, 33, 31, 25, 28, 34, 30, 33, 28, 26, 30, 28...
A Fibonacci sequence, is a sequence of numbers with the property that each number is the...
A Fibonacci sequence, is a sequence of numbers with the property that each number is the sum of the two preceding Fibonacci numbers, starting from 0 and 1. Fibonacci number are usually denoted by Fn, where Fn is the nth Fibonacci number. Thus Fn = 0, and Fn = 1, and Fn = Fn-1 + Fn-2, n ≥ 2. Here are the first few Fibonacci numbers: F0=0 (by definition) F1=1 (by definition) F2 = F1 + F0 = 1 +...
Define a class called Rational for rational numbers. Arational number is a number that can...
Define a class called Rational for rational numbers. A rational number is a number that can be represented as the quotient of two integers. For example, /2, 3/4, 64/2, and so forth are all rational numbers.Represent rational numbers as two private values of type int, numfor the numerator and den for the denominator. The class has a default constructor with default values (num = 0,den = 1), a copy constructor, an assignment operator and three friend functions for operator overloading...
Is rational number divided by an irrational number equal to irrational number or rational number?
Is rational number divided by an irrational number equal to irrational number or rational number? for example such as ( 5 / 2pi )
Take an unknown number of integers as input and print the second smallest number. If there...
Take an unknown number of integers as input and print the second smallest number. If there is no second smallest number in the sequence the program should print an error message and quit. Write a function that takes a vector as argument and that returns an int containing the second smallest number. If no such number exists, the function should throw an exception that in turn is caught in main. Your program should compute its answer with a complexity no...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT