is this pseudocode correct for multiplying 2 integers without using the * function | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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 } }

23rd Aug 2020, 12:20 PM
reeseey
3 Antworten
+ 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.
23rd Aug 2020, 12:44 PM
Brian
Brian - avatar
+ 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 }
23rd Aug 2020, 1:33 PM
zemiak
+ 1
thank you !!
23rd Aug 2020, 3:33 PM
reeseey