Computer Science, asked by swethachowdary845, 9 months ago

Lucy and Tina are close friends. They both are studying in the same school. Now they are on their summer vacation. As they are bored, they ask their parents to take them to an exhibition. There Lucy and Tina play a game. In this game, there are three boxes with some number written on their top. There is a treasure in one of the three boxes and the treasure is present in the box with the second largest number on its top. Also, to open the box, they need to decode the correct code of this box. The clue given to them to find the code is that it is the largest number which divides all the three given numbers. So, now help Lucy and Tina to decode the code.

Answers

Answered by jobastin
16

Answer:

#include<iostream>  

#include<algorithm>  

using namespace std;  

int main()  

{  

 int a,b,c;

 std::cin>>a>>b>>c;

 int sum=6;

 int gp=0,sp=0;

 //finding position of the largest number

 if(a>b && a>c)

  gp=1;

 else if(b>a && b>c)

  gp=2;

 else

  gp=3;

 //finding position of the smallest number

 if(a<b && a<c)

  sp=1;

 else if(b<a && b<c)

  sp=2;

 else

  sp=3;

int x=gp+sp;//adding the positon of largest and smallest number

int y=sum-x;//subustracting it from the positions total(1+2+3=6)

 switch(y)

 {

  case 1:std::cout<<"The treasure is in box which has number "<<a<<

   "\nThe code to open the box is 1";

 break;

 case 2:std::cout<<"The treasure is in box which has number "<<b<<

   "\nThe code to open the box is 2";

 break;

 case 3:

 std::cout<<"The treasure is in box which has number "<<c<<

   "\nThe code to open the box is 3";

 break;

}

return 0;  

}

Explanation:

Answered by komalparkash
0

Answer:

SAMPLE INPUT:

2

6

8

SAMPLE OUTPUT:

Treasure is in the box which has the number 6.

The code to open the box is 2.

Explanation:

#include<stdio.h>

int main()

{

 int a, b, c, max, min, s;

 scanf("%d %d %d", &a, &b, &c);

   if(a>b){

   if(a>c){

     max = a;

   }

   else if(b>c){

     max = b;

   }

   else{

     max = c;

   }

 }

 else if(b>c){

   max = b;

 }

 else if(c>a){

   max = c;

 }

 else{

   max = a;

 }

 if(a==max){

   if(b<c)

     s = c;

   else

     s = b;

 }

 else if(b==max){

   if(a<c)

     s = c;

   else

     s = a;

 }

 else{

   if(a<b)

     s = b;

   else

     s = a;

 }

 printf("Treasure is in the box which has the number %d.\n", s);

 if(a<s){

   min = a;

   if(b%min==0 && c%min==0){

     printf("The code to open the box is %d.", a);

     return 0;

   }

 }

 else if(b<s){

    min = b;

    if(a%min==0 && c%min==0){

     printf("The code to open the box is %d.", b);

     return 0;

   }

 }

 else{

   min = c;

     if(a%min==0 && b%min==0){

     printf("The code to open the box is %d.", c);

     return 0;

   }

 }

}

Learn more from the given links:

Write a program to generate the following series 0,2,8,14,...,34.:-

https://brainly.in/question/16742464

Mr. Myers and the Exam:-

https://brainly.in/question/41082786

Similar questions