Question: Im looking for a basic C program that accepts 2 integers from the user in the main function and calls a function to compute the

Im looking for a basic C program that accepts 2 integers from the user in the main function and calls a function to compute the Greatest Common Denominator and Least Common Multiple of the two numbers. The parameters to the function are the two integers. The result (GCD) is returned as a function return value. After printing the GCD, a function is called to compute the LCM of the two numbers and the result (LCM) is returned as a function return value of the second function.

The main function should prompt the user to enter two positive integer values. If anything other than positive integers are entered, display an error message and prompt them to re-enter two numbers. A while loop must be used to keep accepting inputs if they are invalid. If the set of inputs are valid, call the function to compute GCD first, print the GCD result, then call the second function to compute LCM, print the LCM result, and stop the program. The program does not need to continuously accept numbers.

The functions needs use a for loop to compute the GCD of the two numbers and return the result as a function return value Any logic can be used to compute the LCM of the integers. The results of the computations need to be printed in the main function.

To write the program, this partial starter file must be used.

#include  int gcd(int number1, int number2); int gcd(int number1, int number2) { int result; /* Compute the GCD of the two numbers here using a 'for' loop */ /* Store the GCD in the variable result and return it */ return(result); } int main(void) { /* Accept numbers, validate them to be positive numbers */ /* Otherwise keep accepting numbers until they are both positive using a while loop */ /* If both are positive, call the gcd function to get the result and print */ return(0); }

The output should look something like this.

Im looking for a basic C program that accepts 2 integers from

Please enter 2 positive integers: You entered: 129 and 165 GCD of 129 and 165 is 3 LCM of 129 and 165 is 7095

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!