x
and y
are integers, the function f(x, y) = xy needs to be calculated. Calculate the function f(x, y)
recursively.
#include <stdio.h>
#include <stdlib.h>
int f(int x, int y) {
if (x == 0 && y != 0) {
printf("answer: 0\n");
return 0;
} else if (x != 0 && y == 0) {
printf("result: 1\n");
return 1;
} else if (x > 0 && y == 1) {
f(x, 1) == x;
return x;
} else if (x > 0 && y > 0) {
printf("result: %d\n", x * f(x, y - 1));
return x * f(x, y - 1);
} else {
y = -y;
printf("result: %d\n", 1 / f(x, y));
return 1 / f(x, y);
}
}
int main() {
int k, l;
float result;
printf("*****************ust alma*********************\n\n");
printf("enter two number: ");
scanf("%d\n%d", &k, &l);
result = f(k, l);
printf("girilen result: %d", result);
return 0;
}
I am waiting for your help I can not do this lesson. Really hard for me.