Patrick started to play a card game –XII. In this game, he has to choose three cards, based on the card number present in the third card he will be a winner. With the help of Johnny, he inferred a pattern in the third card number was the Least Common Multiple of first and second card numbers.
So write a C program to help Patrick to choose a third card to make him win this game using while loop.

Input Format:
Input consists of 2 integers, which corresponds to the first and second card respectively.
Output Format:
The output consists of a single line. Refer sample output for details.
 
[All text in bold corresponds to the input and the rest corresponds to output]

Sample Input and Output1:
Enter the first card picked up by Patrick:
15
Enter the second card picked up by Patrick:
9
Patrick must choose next card with the number 45



Program Code:
#include <stdio.h>
int main()
{
    int n1, n2, minMultiple;
    printf("Enter the first card picked up by Patrick:\n");
    scanf("%d", &n1);
    printf("Enter the second card picked up by Patrick:\n");
    scanf("%d", &n2);
    minMultiple = (n1>n2) ? n1 : n2;
    while(1)
    {
        if( minMultiple%n1==0 && minMultiple%n2==0 )
        {
printf("Patrick must choose next card with the number %d", minMultiple);
            break;
        }
        ++minMultiple;
    }
    return 0;

}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: