0 like 0 dislike

Write a program that asks the user to enter two integers, then calculates and displays their greatest common divisor (GCD) and their Least common multiple (LCM).

Hint: Use Euclidean Algorithm

LCM:

In arithmetic and number theory, the least common multiplelowest common multiple, or smallest common multiple of two integers a and b, usually denoted by LCM(ab), is the smallest positive integer that is divisible by both a and b.

What is the LCM of 4 and 6?

Multiples of 4 are:

4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, ...

and the multiples of 6 are:

6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, ...

Common multiples of 4 and 6 are simply the numbers that are in both lists:

12, 24, 36, 48, 60, 72, ....

So, from this list of the first few common multiples of the numbers 4 and 6, their least common multiple is 12.

Example input:

``12 28``

Example output (first number is GCD, second number is LCM):

``4 84``

[Exam] asked in Midterm | 147 views

0 like 0 dislike
`Hidden content!#include <stdio.h>int main(){ **  * ** * ******** **   * * a,b;****     * **    ***  ********  remain=0;*      ** ** **    **    * *** gcd;*  * *    **   *  ****  * *       i,j=1;**  * * *  *****       *    t=0;  *  * ** ** *** **  * * **  *  ** * *  *  * **** **  * ***** * ***  *  ****  * *** * *** ** * **  *  * *****      * * ** gcd*** * ***    *  ** *     ** *    ***** ** * *    **  ******  ********     **     * ***  *  ** of a and b from range a to b  * *  *  *  *        ***** *** * * = a; i <= b; i++){ * ***  * * *****  *   ** * *      *** ***** ***** ****    ** ", i);* ***   **  *  *     *   *  *    * *   * *** *          *  0;}`
answered by (-74 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
`Hidden content!#include  ***  ** *  *   **int main(){ * * * ***    **   ***  **   n1, n2, i, gcd;   **    *  * ** ** * ****    **  ** **   * ***     &n1, &n2);   **   * *   *   ** **   **  *  i <= n1 *  *  * **** i <= n2; ++i) *** *      ***       **  * ** ***  ** *  * **** ** ** * ** *      * * ***     * * *  **  ***    * *     ***  n2%i==0)  * *  ** *** * **    * *** *****  **    ** ***  * *     *  = i; **   * ***     *** *** *** *  ***  **      ** *** * **  *  *** ** *  gcd); *  * ** *   *  ***** *   ***  ** 0;}`
45/100 answered by (-233 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
`Hidden content!#include<stdio.h>int main(){****  *     * *   * * *****  * * *** a,b,c,d,e,m,i;*   ***   *  ** * * **** * ***** *  *    ***  *   ** **  *  * ** * ** ** ***** *  *  *  **   ** * *** * *  *  ***      *     *** **  ** * *  *** *  *  ****** ** **  **  *   *  **   **  *   **    ** * *  *   **  **  * ***       *  *  ***    * *  *  * *  * * * ** ***   *  ****** **  *  **  * * *   * * * *   ** * **    * *  *     }    if (a%b==0){   ** *** **    * *** *     *** *  * ** * ***  ***  **    **** **** * ** *  *  * *    }*  * ** *     *  *   * *** ******    ** * ** *  ** *   *   ***   ***      *  *  ** * ****  *** *   ** *** ** *** *  ***  *   ** **       ** ** *   * **  * **  ****   * ** ****  ***     ** * **** *    * * *   *  **** ***   *  *  **   *** ** *  ** *   * * *  **   *       ***  ** ***   * **   ***      *   *****  *  %d",i);* ***   **   *   **** **   * *    ******  *   *  ******* * *     * **       ** *** *  *   * **  ****** *  **  *   ****** *    * *     * *  **** * *  * *  ** ***       **** *  ** *  **   **   **     **   *    * *  * ****** **     }   return 0;}`
answered by (-32 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Wrong output
Case 4: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Wrong output
Case 4: Correct output
0 like 0 dislike
`Hidden content!**  * ** *  ***  *int main (){int  * *****  * *** * * *** * *   * * * *    *   ** **   **  * **  * ***  **   * ***   * ** * *  **   * *  * * *  * **     ** **   *  **    *else{ * **** **  *   *       *   }}return 0;}`
answered by (16 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
`Hidden content!*** *** ***  *  *   *int main(void){int *   ****  *    *  ** * ** * *     **    *** **********  *   * *   * ***  ***** * **    *{***   **    *    ** * *  *   ** **** ** **  **         **    ***  ***  * *  * }lcm=n*n2/gcd; *  * *** * * * ** *** ** **return 0;}`
answered by (-167 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
`Hidden content!#include <stdio.h>#include <stdlib.h>int main(){  ** *  *** **  **** **   num1;**  * * *   *    *   *   *    * num2;*   *** * * *   * * * *** *   ** remainder;  * *** ******   * *  * **    numerator; *  **** **  *** * ** **   denominator; ** ** *  * *  ** ** * *       gcd, lcm;*** *  ** *********   ****  **   ******   *  *** **  ** ****    ****   *     * **     *  ***** ****    ** ** * * *** ** * ** *** *  * * *   ***  **     * *** * * * * *  *   **    *** *  ** * *  * ***  * * ****     *    ** **  * **  * *** * **   *     **** * ** *    * *     }**** ****  **     *   ****   *  *   ***  *  *  * *  ****  ***** **     *    ******** *    **  ****    *********  *****  *   *   *  *     **     ** *  *  *** *  * * * * **   *  * *   * ** *   * *  **   **  ** **  ** ** *    } ****** * **   **  ** * ** *   *  ***  ****  **** ***  **** *  * **   *   ***** *** * != 0)    {*** *  *   * * ***  *  **    * * *     * * * **  *  *** **** ** *  ** ** * *     ***  *  *   * * *****  ** ** * *  ***  *  **    **** *  * *** **** *   *    **    **  ***  **  ** * * ****       **** * **** *  *    }**  *   *  *   * *  *  ******  * *  *  **  *  ******  ***  *  **  *  *  * * *  **     **   **  ** * ** ***   *****   ** ",gcd);   ** *  *  **  ***    ** ** * ** ***   *   *******   *       * **** **  *** * * * * 0;}`
answered by (-193 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
`Hidden content!* *** *   ****  *** **int main(){int a,b,i,n,gcd,lcm; ** * *   ***   *   *** **  * * **      **   * *  *{*     *       *   ***** ***  *  *     *   *     **   * ****  ****   * * * *****  ***** **** *  * **   ** }lcm=a*b/gcd;** ** ***   *   ***  *  ***  return 0;}`
answered by (-32 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
`Hidden content!#include<stdio.h>int gcd(int x,int y){*  ** * * *** *       * *** **  z;* ** *   * ***** * *   ** *      * * **     { * ****  *  * ****   **** **    *  ****  * **  ***** ***   * *   * *** *  * *   *** ***    *    * ** ****  ** **  * ** *        ****   *** * ***  ********     **    ****    * ***  ******    ***  ***     * ** *** ******* **     ***   **   **    * *  **  * *   *  * *****  **      *  * * *     *   *** * * ** *  *    *****  * ** *  *** *  **  *   ****  ** *      *  ****** **  *  ******  *    **      * ** y;    } * *     *  * * ** ***   ** ****** *    {*       ** * ** *  **** ** *  *   ******  ***** *     ** ** * *  * *       * ***    *  ******* *** * *  **  *** **     ** **** * ***** *    * **  *  * **  * ****   *   *   *     ** *     ** *** * ****  *** * * ** ***  *   ****  **    * * ***** *  *** *  *** ** **  **  * ** *   *** **  *  *** ** ** ** * ** ***** *  * **       ****   *  *    * * ****  *  ** *  *  * *  **  *   *** *** * *** * ** *   *  * ** *** ***  *  * **  ****** **   * ******* *   *    *   *** ** x;    }}int main(){    int a,b,lcm;   **   ****   * *** *  **** *** * *** %d",&a,&b); ***  *** ** *  *  *   ***  ** * *   ** **** ** *   **  **  *** ** *** * * * **    * *   * *  *** **   *  *** *  ** * %d",gcd(a,b),lcm);}`
answered by (-255 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
`Hidden content!#include <stdio.h>#include **      ** int main(){ * ** *  * *  *   ** * ** a,b,i,j;*****   ** * **** * *** *   ** *  **      *      **     **  ***    *     ***  *** *** * **  ***    * i>=1; i--)* *  *  **  ***      ** ***  *** * * *** * *** * *   *    **  *  *  **  *   **   (a%i==0 && b%i==0)***** **   ***  *   ***  *  **   *  *     *    * **  * * *   ** *  * *  **** *** **  * *  ** *     ***  ** *  *     *** ***  **   * **  * *       * ** * ** * * j<=a*b; j++)**     ** ******   *      ***  ** * **   *   *     * *   *** **  **  ** * *    *     ** * (j%a==0 && j%b==0) * *** *    *  **  * *   *  *   * **  * *  ***  **** * ****   *  * * *  *   * ***  *  * *  ** * ***  * *****   *** * *     *  *** ** *   *   *     **  %d",j);* * * *** ** ****  **     ****** 0;}`
answered by (-127 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
`Hidden content!#include<stdio.h>int main(void){ *  ***** *  * ** **** * ** *  * a,b;**   ***       * **   *   * ** **   * ** * %d",&a,&b); *  * * *  ** * ***** ***  i,gcd,lcm; ****   *  * *    * **** ** ** **     * *** *  *   **  * *   *       *   *  **  *    * *** *      **** *** *    *  ***** *** * * *   ** && b%i==0) * *  **   *  * *     *** ** * *****  *   * * *  *   * **** * **  *  ***** ** ** *  * * **     *        ***  ****  **  *   *   ** * *  * ** *      **  ***   *   ***   ***   * ***   *  * *   **       ** * ***     * * ***  ****** *  * ** *    * ** ***   * ****** *** * *   ******      * %d",gcd,lcm);}`
answered by (-249 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output