Jawaban Soal I, versi Algoritma - Ilmu.org

7 downloads 352 Views 11KB Size Report
Jawaban Soal I, versi Algoritma. Algoritma chekDidalam(x, vArrData). //input: x is integer, vArrData is Array of Integer. //output: vFind boolean. vTerus ← true.
Jawaban Soal I, versi Algoritma Algoritma chekDidalam(x, vArrData) //input: x is integer, vArrData is Array of Integer //output: vFind boolean vTerus  true vFind  false i  0 while ((i< vArrData.length) and (vTerus)) do if (x == vArrData[i]) then vTerus  false vFind  true end i++ end return vFind end

Algoritma excludeElement(vA, vB) //input: vA, vB are Array of Integer //output: vC is Array of Integer vC  [] k  0 for i=1 to vA.length do if not (chekDidalam(vA[i], vB)) then vC[k] = vA[i] k++ end end return vC end

Algoritma findSameElement(vA, vB) //input: vA, vB are Array of Integer //output: vC is Array of Integer vC  [] k  0 for i=0 to vA.length do if (chekDidalam(vA[i], vB)) vC[k]  vA[i] k++ end end return vC end

Algoritma randomAgeBetween(nA, nB, m) //input: nA, nB, m are Integer //output: vC is Array of Integer vAge  [] vTerus  true while (vTerus) do tmpUsia  randomInteger if ((tmpUsia >= nA) and (tmpUsia