0% found this document useful (0 votes)
30 views5 pages

Array Operations Pseudocode Guide

Uploaded by

leeminknow258
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views5 pages

Array Operations Pseudocode Guide

Uploaded by

leeminknow258
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

✅Question 1: Total and Average of Array

Pseudocode:

DECLARE numbers[1:10] ARRAY AS INT , total = 0, average

FOR i ← 0 TO 9

OUTPUT "Enter number ", i + 1

INPUT numbers[i]

total ← total + numbers[i]

NEXT i

average ← total / 10

OUTPUT "Total is ", total

OUTPUT "Average is ", average

✅Question 2: Count Even and Odd Numbers

Pseudocode:

DECLARE numbers[1:20 ARRAY AS INT], evenCount = 0, oddCount = 0

FOR i ← 0 TO 19

OUTPUT "Enter number ", i + 1

INPUT numbers[i]

IF numbers[i] MOD 2 = 0 THEN

evenCount ← evenCount + 1

ELSE

oddCount ← oddCount + 1

ENDIF
NEXT i

OUTPUT "Even numbers: ", evenCount

OUTPUT "Odd numbers: ", oddCount

✅Question 3: Find Maximum and Minimum in Array

Pseudocode:

DECLARE numbers[1:15] ARRAY AS INT

OUTPUT "Enter number 1"

INPUT numbers[0]

max ← numbers[0]

min ← numbers[0]

FOR i ← 1 TO 14

OUTPUT "Enter number ", i + 1

INPUT numbers[i]

IF numbers[i] > max THEN

max ← numbers[i]

ENDIF

IF numbers[i] < min THEN

min ← numbers[i]

ENDIF

NEXT i

OUTPUT "Maximum is ", max

OUTPUT "Minimum is ", min


✅Question 4: Search for a Value in Array

Pseudocode:

DECLARE studentIDs[10], found = FALSE, searchID

FOR i ← 0 TO 9

OUTPUT "Enter Student ID ", i + 1

INPUT studentIDs[i]

NEXT i

OUTPUT "Enter ID to search: "

INPUT searchID

FOR i ← 0 TO 9

IF studentIDs[i] = searchID THEN

found ← TRUE

BREAK

ENDIF

NEXT i

IF found = TRUE THEN

OUTPUT "ID found in the list"

ELSE

OUTPUT "ID not found"

ENDIF
✅Question 5: Replace Negative Numbers with Zero

Pseudocode:

DECLARE numbers[10]

FOR i ← 0 TO 9

OUTPUT "Enter number ", i + 1

INPUT numbers[i]

IF numbers[i] < 0 THEN

numbers[i] ← 0

ENDIF

NEXT i

OUTPUT "Modified array:"

FOR i ← 0 TO 9

OUTPUT numbers[i]

NEXT i

✅Question 6: Reverse an Array

Pseudocode:

DECLARE numbers[8]

FOR i ← 0 TO 7

OUTPUT "Enter number ", i + 1

INPUT numbers[i]

NEXT i
OUTPUT "Array in reverse:"

FOR i ← 7 TO 0 STEP -1

OUTPUT numbers[i]

NEXT i

✅Question 7: Sum of Positive and Negative Numbers

Pseudocode:

DECLARE numbers[10], posTotal = 0, negTotal = 0

FOR i ← 0 TO 9

OUTPUT "Enter number ", i + 1

INPUT numbers[i]

IF numbers[i] > 0 THEN

posTotal ← posTotal + numbers[i]

ELSE IF numbers[i] < 0 THEN

negTotal ← negTotal + numbers[i]

ENDIF

NEXT i

OUTPUT "Sum of positive numbers: ", posTotal

OUTPUT "Sum of negative numbers: ", negTotal

Common questions

Powered by AI

The pseudocode initiates 'max' and 'min' with the first array element. It iterates through the rest of the array, updating 'max' if a higher value is found, and 'min' if a lower value is found. This approach effectively requires a single pass through the array, making it an efficient O(n) algorithm for finding extrema .

The pseudocode captures inputs for an 8-element array, then prints the elements in reverse order. The effectiveness lies in its simplicity, using a backward index in a single loop to output elements. This approach effectively reverses the array with a complexity of O(n) but does not store the reversed order if such need arises in future computation .

The pseudocode initializes two counters, 'evenCount' and 'oddCount', both set to 0. It iterates over an array of 20 integers, checking each element's parity using the modulo operator. If an element is even, it increments 'evenCount'; otherwise, it increments 'oddCount'. The process uses a loop and a conditional statement for control flow .

The pseudocode initializes 'posTotal' and 'negTotal' to zero. It iterates through each element of a 10-item array, adding to 'posTotal' if the element is positive, or subtracting from 'negTotal' if negative. This separation relies on conditional checks within a loop, effectively handling the task in linear time or O(n).

The pseudocode uses a linear search algorithm. It loops through the array of 10 elements, comparing each with 'searchID'. If found, it sets 'found' to TRUE and breaks out of the loop. Given the simplicity and size (10 elements), this O(n) approach is straightforward and sufficient, though not optimal for larger arrays where binary search could be more efficient .

The pseudocode sequentially requests input for an array of 10 integers, storing them in 'numbers'. It initializes 'total' to 0, then iteratively adds each element to 'total'. After processing all inputs, it calculates the average by dividing 'total' by 10. Finally, it outputs both the total and the average .

The pseudocode iterates through an array of 10 numbers, checking each for negativity. If a number is negative, it's replaced with zero. This replacement operation involves a single loop, giving a time complexity of O(n), where n is the number of elements in the array .

You might also like