0
is this pseudocode correct for multiplying 2 integers without using the * function
multi(int h, int i,int j) { j <- 0 If (h=0 || i=0) return 0; Else if (i>0) For (int k=0, k<i,k++){ Return j = j+h } }
3 ответов
+ 2
It is not quite correct. Because the return statement is inside the loop, it exits immediately during the first iteration and never gets to do a second iteration.
Also, it does not handle the case when i<0.
+ 1
// for i>0:
multi(int h, int i) { // two parameters
j = 0
If (h=0 || i=0)
return 0;
Else if (i>0)
For (int k=0, k<i, k++){
j = j+h
}
return j //return here
}
+ 1
thank you !!