108k views
1 vote
Give a recursive algorithm that takes as input two positive integers x and y and returns the product of x and y. The only arithmetic operations your algorithm can perform are addition or subtraction. Furthermore, your algorithm should have no loops.

1 Answer

5 votes

Answer:

#include <stdio.h>

int product(int x,int y)

(

if(y==1)

return x;

else

return (x+product(x,y-1));

)

int main()

(

int a,b;

scanf("%d %d",&a,&b);

printf("%d\\*,product(a,b));

return 0;

)

Step-by-step explanation:

See above code as explanatory enough.

User Yasser Mohsen
by
5.6k points