Ive figured out how to do the GCD/LCM part -- I need some help with the input va
ID: 3873345 • Letter: I
Question
Ive figured out how to do the GCD/LCM part -- I need some help with the input validation though
Basic Problem (80 pts): Given two integers, write a program to find the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of them Your assembly implementation should follow the pseudo code sequence given below. Please do not perform any optimization at pseudo code level or at assembly level. Input validation (20 pts): The input numbers need be in range [0, 255]. Besides, both inputs cannot be zero at the same time since GCD(0,0) is undefined. So, you should verify the input numbers are valid.Explanation / Answer
The validation part is completed in following code:
int main()
{
int n1, n2;
printf("Enter first integer n1:");
scanf("%d",&n1);
printf("Enter Second integer n2:");
scanf("%d", &n2);
if( n1 == 0 && n2 ==0 )
{
printf("The n1 = 0 and n2 = 0, hence GCD is undefined");
}
else if( n1 >= 0 && n1 <= 255 && n2 >=0 && n2 <= 255)
{
printf("The greatest common divisor of n1 and n2 is %d ", gcd(n1,n2));
printf("The least common multiple of n1 and n2 is %d ", lcm(n1,n2));
}
else
{
Printf("Entered Number n1 / n2 is not in range [0, 255]");
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.