Assume the arrays nbrArray1 and nbrArray2 each have 10 elements. Design an algorithm that copies the values in nbrArray1 to nbrArray2 using a FOR Loop.
Please write in pseudocode, thanks
Algorithm:
1. START
1 STEP: Given Arrays nbrArray1 and nbrArray2.
2 STEP: Let m= nbrArray1[10] is the given size of Array.
3 STEP: Let n= Elements of nbrArray1 like ( 1, 5,4,8,7,11,9,21,-3,14).
4 STEP: Let k= nbrArray2[10] to store the copy of nbrArray1
5 STEP: To copy all elements of nbrArray1 to nbrArray2 , we need to iterate every element of nbrArray1.
6 STEP: Hence a FOR loop should iterate from 0 to m which is the size of the given Array like ( For i=0; i<m; i++)
7 STEP: In the loop assign current array of m to k like k[i]=m[i]
8 END.
PSEUDOCODE:
Procedure copy_array( nbrArray1, nbrArray2)
SET index to 1
FOR Each value in nbrArray1 Do
nbrArray2[index]= nbrArray1[index]
INCREMENT index
END FOR
end procedure
Get Answers For Free
Most questions answered within 1 hours.