Commit b6ed422c authored by Believer Programmers' Club's avatar Believer Programmers' Club

Merge branch 'exe_51' into 'master'

exercise_06_51, version1

See merge request bpcarm/trainings2017!1322
parents 579b7015 9a713f06
progname = exercise_06_51
CC = g++
CFLAGS = -Wall -Wextra -Werror -g3
$(progname): $(progname).o | .gitignore
$(CC) $(CFLAGS) $^ -o $@
%.ii: %.cpp
$(CC) -E $(CFLAGS) $< -o $@
%.s: %.ii
$(CC) -S $(CFLAGS) $< -o $@
%.o: %.s
$(CC) -c $(CFLAGS) $< -o $@
.gitignore:
echo $(progname) > $@
clean:
rm -f *.ii *.s *.o *.out $(progname) .gitignore
test%: $(progname)
./$(progname) < $@.in > $@.out
diff $@.out $@.expected && echo PASSED || echo FAILED
.PRECIOUS: $(progname).ii $(progname).s
.SECONDARY: $(progname).ii $(progname).s
#include <iostream>
#include <cmath>
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,y) << std::endl;
return 0;
}
int
mystery(int a, int b)
{
if (0 == b) {
return 0;
}
if (b < 0) {
b = -b;
a = -a;
}
return a + mystery(a, b - 1);
}
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