Function Main
Declare Integer fact1
Declare Integer fact2
Output " First factor"
Input fact1
Output "Second factor"
Input fact2
Output multiply(fact1, fact2)
End
Function multiply (Integer x, Integer y)
Declare Integer result
If y = 0
Assign result = 0
End
If y > 0
Assign result = x + multiply(x, y-1)
End
If y < 0
Assign result = -multiply(x, -y)
End
Return Integer result
#include <stdio.h>
int multiply(int x, int y);
int main() {
int fact1;
int fact2;
printf("First factor:\n");
scanf("%d", &fact1);
printf("Second factor:\n");
scanf("%d", &fact2);
printf("%d\n", multiply(fact1, fact2));
return 0;
}
int multiply(int x, int y) {
int result;
if (y == 0) {
result = 0;
}
if (y > 0) {
result = x + multiply(x, y - 1);
}
if (y < 0) {
result = (int) (-multiply(x, (int) (-y)));
}
return result;
}
I am Md. Anisur Rahman. I have completed Cyber Security for MSCSE at United International University in 2022.I have completed PGDIT from IIT, Jahangirnagar University in 2020. I'm a Head of IT at Programming24 School.
View all posts by Md. Anisur Rahman