Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C basic programming language Write the function int(gcd b, a); Compose a main

ID: 3624419 • Letter: I

Question

In C basic programming language
Write the function
int(gcd b, a);
Compose a main function that demonstrates the gcd function. The main function should ask for b and a and output the message

The gcd of b and a is gcd(b, a)
for each pair of b and a input.

Main function should exit (return 0) when both b and a are zero.
For example the output should look like this:
Enter b and a> 32 5
The gcd of 32 and 5 is 1
Enter b and a> 250 15
The gcd of 250 and 15 is 5
Enter n and m> 0 0

the gcd is the greatest common divisor which is defined as 2 integers is the largest number that can evenly be divided into them as well.
The algorithm to computate the gcd of two integrs, a and b is as shows:
1) The gcd of non positive numbers is the same as the positive. So one should take the absolute value.
2) One of the numbrs is 0, the other is therefore the gcd.
3) Substitute the larger numbr with the remainder of dividing the bigger by the number that is smaller or lesser.
4) Substitute step three until 1 of the numbrs is 0.


Explanation / Answer

please rate - thanks

# include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int gcd(int,int);
int main()
{
   int a;       
   int b;
    printf("The gcd of b and a is gcd(b, a) ");
printf("for each pair of b and a input. ");
   for(; ;)
   {       

printf("Enter b and a> ");
scanf("%d",&b);
scanf("%d",&a);
if(a==b&&b==0)
       return 0;
   printf("The GCD of %d and %d is %d ",a,b,gcd(a,b));
   }

  
}
int gcd(int a, int b)  
{ int big,small;
a=abs(a);
b=abs(b);
for(; ;)
{
if(a==0)
     return b;
if(b==0)
     return a;
if(b<a)
     {small=b;
     big=a;
     }
else
     { small=a;
      big=b;
     }
big%=small;
a=big;
b=small;
}

}