Question: Description: Complete the following C programming exercises. Each program must include a comment header and line comments. Question 1: The least common multiple (lcm) of
Description: Complete the following C programming exercises. Each program must include a comment header and line comments.
Question 1: The least common multiple (lcm) of two positive integers u and v is the smallest positive integer that is evenly divisible by both u and v. Thus, the lcm of 15 and 10, written lcm(15, 10), is 30 because 30 is the smallest integer divisible by both 15 and 10. Write a function lcm() that takes two integer arguments and returns their lcm. The lcm() function should calculate the least common multiple by calling the gcd() function from program 7.6 (Listed Below) in accordance with the following identity:
lcm(u, v) = uv / gcd(u, v) u, v >= 0
program 7.6
/* Function to find the greatest common divisor of two
nonnegative integer values and to return the result */
#include
int gcd (int u, int v)
{
int temp;
while ( v != 0 ) {
temp = u % v;
u = v;
v = temp;
}
return u;
}
int main (void)
{
int result;
result = gcd (150, 35);
printf ("The gcd of 150 and 35 is %i ", result);
result = gcd (1026, 405);
printf ("The gcd of 1026 and 405 is %i ", result);
printf ("The gcd of 83 and 240 is %i ", gcd (83, 240));
return 0;
}
Question 2: Write a function called arraySum() that takes two arguments: an integer array and the number of elements in the array. Have the function return as its result the sum of the elements in the array.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
