Using Namespace Bool Int Int If Return True If Return False If Return True If Return False Int If

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

#include<iostream>

using namespace std;


bool bear(int n)
{
int result,b,c;
result=2;
if(n==42)
return true;
if(n!=42)
return false;
if(result==1)
return true;
if(result==0)
return false;
int a;
a=n%5;
if((a==0)&&(result==2)){
result=bear(n-42);
a=n%4; // If n is divisible by 3 or 4, then you may multiply
the last two digits of n and //give back this many bears
}
if((a==0)&&(result==2))
{
b=n%10;
c=((n%100)-b)/10;
if((b!=0)&& (c!=0))
result=bear(n-c*b);
}
a=n%3; // If n is divisible by 3 or 4, then you may multiply
the last two digits of n and // give back this many bears.
if((a==0)&&(result==2))
{
b=n%10;
c=((n%100)-b)/10;
if((b!=0)&&(c!=0))
result=bear(n-c*b);
}
a=n%2; // If n is even, then you may give back exactly n/2
bears
if((a==0)&&(result==2))
result=bear(n/2);
else if(result==2)
false;

if(result==1)
true;
if(result==0)
false;

return n;
}
int main() // The game starts when I give you some bears
{
int n;
bool result;
cout<< "please enter count of bears : ";
cin>>n;
result=bear(n);
if(result==true)
cout<< "true";
else
cout<<"false";
}

#include <iostream>
bool bear(int n)
{
int result,b,c;
result=2;
if(n==42) return true;
if(n!=42) return false;
if(result==1)return true;
if(result==0)return false;
int a;
a=n%5;
if(a==0&amp;&amp;result==2)result=bear(n-42);
a=n%4; // If n is divisible by 3 or 4, then you may multiply
the last two digits of n and //give back this many bears
if(a==0&amp;&amp;result==2)
{
b=n%10;
c=((n%100)-b)/10;
if(b!=0&amp;&amp;c!=0) result=bear(n-c*b);
}
a=n%3; // If n is divisible by 3 or 4, then you may multiply
the last two digits of n and // give back this many bears.
if(a==0&amp;&amp;result==2)
{
b=n%10;
c=((n%100)-b)/10;
if(b!=0&amp;&amp;c!=0)result=bear(n-c*b);
}
a=n%2; // If n is even, then you may give back exactly n/2
bears
if(a==0&amp;&amp;result==2) result=bear(n/2);
else if(result==2)return false;
if(result==1)return true;
if(result==0)return false;
}
int main() // The game starts when I give you some bears
{
int n;
bool result;
printf(&quot;please enter count of bears : &quot;);
scanf(&quot;%d&quot;,&amp;n);
result=bear(n);
if(result==true) printf(&quot; true&quot;);
else printf(&quot; false&quot;);

scanf(&quot;%d&quot;,&amp;n);
}

You might also like