Computer Science, asked by KrishabhKr, 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.
Input (stdin)
7
5
6
Output (stdout)
The treasure is in box which has number 6
The code to open the box is 1

Answers

Answered by Daisyduck
4

#include<iostream>

using namespace std;

int main()

{

int a,b,c;

int x,y,z,hcf,st;

cin>>a>>b>>c;

x=a;

y=b;

z=c;

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

{

if(b >= c)

{

cout<<"The treasure is in box which has number "<<b<<"\n";

}

else

{

cout<<"The treasure is in box which has number "<<c<<"\n";              }

}

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

{

if(a >= c)

{

cout<<"The treasure is in box which has number "<<a<<"\n";

}

else

{

  cout<<"The treasure is in box which has number "<<c<<"\n";

}

}

else if(a >= b)

{

cout<<"The treasure is in box which has number "<<a<<"\n";

}

else

{

 cout<<"The treasure is in box which has number "<<b<<"\n";

}

st=x<b?(x<z?x:z):(y<z?y:z);

for (hcf=st;hcf>=1;hcf--)

{

 if (a%hcf==0 && b%hcf==0 && c%hcf==0)

 break;

}  

 cout<<"The code to open the box is "<<hcf;

}

Answered by pratikkohad1999
3

Answer:

#include<iostream>

using namespace std;

int main()

{

int x,b,c,i,t,s1;

std::cin>>x>>b>>c;

if(x>b && x>c)

{

if(b>c){s1=b;}

else{s1=c;}

}

else if(b>x && b>c){

if(x>c){s1=x;}

else{s1=c;}}

else{if(x>b){s1=x;}

else{s1=b;}

}

std::cout<<"The treasure is in box which has number "<<s1<<"\n";

for(i=1;i<=5;i++){

if(x%i==0 && b%i==0 && c%i==0){

 t=i;

}

}

std::cout<<"The code to open the box is "<<t;

}

Explanation:

Similar questions