Array in Programming
Array in Programming
If you need to access or manipulate the car names, you can do so using standard list operations.
For example:
Write a python in array that will store names of the car as Saab,Volvo,BMW
print(car_names)
Here’s an example Python program that uses an array (list) to store grades of students:
if grades:
print("Grades of students:")
for i, grade in enumerate(grades, start=1):
print(f"Student {i}: {grade}")
else:
print("No grades available.")
if choice == "1":
try:
grade = float(input("Enter the grade: "))
add_grade(grade)
except ValueError:
print("Please enter a valid number.")
elif choice == "2":
display_grades()
elif choice == "3":
calculate_average()
elif choice == "4":
print("Exiting program. Goodbye!")
break
else:
print("Invalid choice. Please try again.")
Explanation:
You can extend this program further by adding more features, such as removing grades or
validating user inputs more robustly.
ARRAY IN PSEUDOCODE
Sure! Let's break down arrays in pseudocode step by step with simple explanations and
examples.
What is an Array?
An array is a collection of elements, all stored together in a specific order. Each element in the
array can be accessed by its index (position in the array). Think of it like a list of items stored in
a row.
Declaration of an Array
For example:
You can assign values to specific positions in the array using the index (starting from 0 or 1,
depending on the convention).
numbers[0] ← 10
numbers[1] ← 20
numbers[2] ← 30
numbers[3] ← 40
numbers[4] ← 50
FOR i ← 0 TO 4
PRINT numbers[i]
END FOR
10
20
30
40
50
Common Operations
4. Updating an Element:
5. numbers[2] ← 35
6. Summing Elements:
7. sum ← 0
8. FOR i ← 0 TO LENGTH(numbers) - 1
9. sum ← sum + numbers[i]
10. END FOR
11. PRINT sum
FOR i ← 0 TO 2
PRINT names[i]
END FOR
Output:
Alice
Bob
Charlie
Explanation: