Bird
0
0
DSA Cprogramming~30 mins

Array Deletion at Middle Index in DSA C - Build from Scratch

Choose your learning style9 modes available
Array Deletion at Middle Index
📖 Scenario: You have a list of daily temperatures recorded in an array. Sometimes, the middle day's temperature is incorrect and needs to be removed to keep the data accurate.
🎯 Goal: Build a program that deletes the middle element from an array of temperatures and shows the updated list.
📋 What You'll Learn
Create an integer array called temps with exactly 7 values: 23, 25, 22, 20, 24, 26, 21
Create an integer variable called size and set it to 7
Write code to delete the middle element (index 3) from the temps array by shifting elements left
Print the updated array elements separated by spaces
💡 Why This Matters
🌍 Real World
Deleting incorrect or unwanted data points from sensor readings or logs is common in data cleaning.
💼 Career
Understanding array manipulation is fundamental for software developers working with low-level data or embedded systems.
Progress0 / 4 steps
1
Create the temperature array
Create an integer array called temps with these exact values: 23, 25, 22, 20, 24, 26, 21.
DSA C
Hint

Use int temps[7] = {23, 25, 22, 20, 24, 26, 21}; to create the array.

2
Set the size variable
Create an integer variable called size and set it to 7.
DSA C
Hint

Use int size = 7; to store the array length.

3
Delete the middle element
Write a for loop with variable i starting from 3 to size - 2 that shifts elements left in the temps array to delete the middle element at index 3. Then decrease size by 1.
DSA C
Hint

Use a for loop from 3 to size - 2 and assign temps[i] = temps[i + 1]; inside the loop. Then reduce size by 1.

4
Print the updated array
Write a for loop with variable i from 0 to size - 1 to print each element of temps separated by spaces.
DSA C
Hint

Use a for loop to print each element with printf("%d", temps[i]); and print a space after each except the last.