Write a program that reads two integers $$X$$ and $$Y$$, and does the following:

  • $$X$$ takes the value of $$Y$$ if ($$X \leq Y$$ or $$Y$$ is a divisor of $$X$$)
  • $$Y$$ takes the value of $$X$$ if ($$X \geq 30$$ and $$Y$$ is a multiple of $$X$$)

Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>

int main()
{
    int X, Y;
    printf("Enter 2 integers: ");
    scanf("%d %d",&X, &Y);
    
    
    printf("Before X=%d, Y=%d\n",X,Y);
    
    if(X<=Y || X%Y==0)
        X=Y;
    else
       if(X>=30 && Y%X==0)
            Y=X;

    printf("After X=%d, Y=%d\n",X,Y);
    
    return 0;
}
 

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Priority Queue and Min heap