Bird
0
0
DSA Cprogramming~30 mins

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

Choose your learning style9 modes available
Array Insertion at Middle Index
📖 Scenario: You are managing a list of daily temperatures recorded in an array. Sometimes, a new temperature reading arrives that needs to be inserted exactly in the middle of the current list to keep the order balanced.
🎯 Goal: Build a program that inserts a new temperature value into the middle of an existing array and then prints the updated array.
📋 What You'll Learn
Create an integer array called temps with exactly 5 values: 23, 25, 22, 24, 26
Create an integer variable called new_temp and set it to 27
Write code to insert new_temp into the middle index of temps, shifting elements to the right
Print the updated array elements separated by spaces
💡 Why This Matters
🌍 Real World
In real life, inserting data into the middle of a list is common when managing ordered records like temperature logs, event schedules, or priority queues.
💼 Career
Understanding how to manipulate arrays and insert elements is a fundamental skill for software developers working with low-level data structures, embedded systems, or performance-critical applications.
Progress0 / 4 steps
1
Create the initial array
Create an integer array called temps with these exact values: 23, 25, 22, 24, 26
DSA C
Hint

Use int temps[6] = {23, 25, 22, 24, 26}; to create the array with space for one extra element.

2
Add the new temperature variable
Create an integer variable called new_temp and set it to 27
DSA C
Hint

Declare int new_temp = 27; inside main().

3
Insert the new temperature at the middle index
Write code to insert new_temp into the middle index 2 of temps, shifting elements from index 2 to the right
DSA C
Hint

Shift elements from the end to index 3 to make space at index 2, then assign new_temp to temps[2].

4
Print the updated array
Use a for loop with variable i from 0 to 5 to print each element of temps separated by spaces
DSA C
Hint

Use printf inside a loop to print each element with a space, then print a newline.