Commit 9a713f06 authored by Karine's avatar Karine

exercise_06_51, finally

parent ec929d6c
#include <iostream>
#include <cmath>
int mystery(const int, const int);
int mystery(int, int);
int main()
{
......@@ -13,20 +14,16 @@ int main()
}
int
mystery(const int a, const int b)
mystery(int a, int b)
{
if(b < 0) {
if(-1 == b) {
return -a;
}
return -a + mystery(a, b + 1);
} else {
if(1 == b) {
return a;
}
return a + mystery(a, b - 1);
if (0 == b) {
return 0;
}
if (b < 0) {
b = -b;
a = -a;
}
return a + mystery(a, b - 1);
}
#include <iostream>
#include <cassert>
int mystery( int, int );
int main()
{
int x, y;
std::cout << "Enter two integers: ";
std::cin >> x >> y;
std::cout << "The result is " << mystery( x, у ) << std::endl;
return 0;
}
int
mystery( int a, int b )
{
assert(b >= 0);
return a + mystery( a, b );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment