A smiling programmer pointing to a sticky note with 'code' written on it in an office setting.

15 Practice Questions on 1D Arrays in C

1. Delete an Element from an Array

Problem: Write a program in C to take an array of size n from the user. Also, take an index from the user and delete the element at the given index.

Example Output:

Enter size of array: 5  
Enter array elements: 1 2 3 4 5  
Enter the index to delete: 3  
The updated array is: 1 2 3 5  

2. Insert an Element into an Array

Problem: Write a program in C to take an array of size n from the user. Then, take an element and an index from the user and insert the element at the given index.

Example Output:

Enter size of array: 5  
Enter array elements: 1 2 3 4 5  
Enter the element to insert: 6  
Enter the index to insert: 1  
The updated array is: 1 6 2 3 4 5  

3. Split an Array into Two Parts

Problem: Write a program in C to take an array of size n and an index from the user. Split the array into two parts from the given index.

Example Output:

Enter size of array: 6  
Enter array elements: 1 2 3 4 5 6  
Enter the index: 3  
The first array: 1 2 3  
The second array: 4 5 6  

4. Add Two Arrays

Problem: Write a program in C to take two arrays of the same size from the user. Add both arrays and store the result in a third array.

Example Output:

Enter size of array: 4  
Enter 1st array: 1 2 3 4  
Enter 2nd array: 5 6 7 8  
The resulting array is: 6 8 10 12  

5. Compute Square of Each Element

Problem: Write a program in C to take an array from the user and compute the square of each element, storing it in a new array.

Example Output:

Enter size of array: 5  
Enter array elements: 1 2 3 4 5  
The resulting array is: 1 4 9 16 25  

6. Search for an Element in an Array

Problem: Write a program in C to take an array from the user and search for an element, returning its index if found.

Example Output:

Enter size of array: 5  
Enter array elements: 5 6 7 8 9  
Enter the element to search: 7  
Element found at index 2  

7. Count the Occurrences of an Element

Problem: Write a program in C to take an array and an element from the user. Count how many times the element appears in the array.

Example Output:

Enter size of array: 5  
Enter array elements: 1 4 3 4 5  
Enter the element to search: 4  
The element occurs 2 times  

8. Count Even and Odd Elements in an Array

Problem: Write a program in C to count the number of even and odd elements in an array.

Example Output:

Enter size of array: 5  
Enter array elements: 7 4 6 4 5  
Total even elements: 3  
Total odd elements: 2  

9. Insert an Element in a Sorted Array

Problem: Write a program in C to take a sorted array and insert an element while maintaining the sorted order.

Example Output:

Enter size of array: 4  
Enter sorted array elements: 5 6 8 9  
Enter the element to insert: 7  
The updated array is: 5 6 7 8 9  

10. Merge Two Arrays

Problem: Write a program in C to merge two arrays into a third array.

Example Output:

Enter size of array: 4  
Enter 1st array elements: 1 2 3 4  
Enter 2nd array elements: 5 6 7 8  
The resulting array is: 1 2 3 4 5 6 7 8  

Additional Questions

11. Reverse an Array

Problem: Write a program in C to reverse the elements of an array.

12. Find the Maximum and Minimum Element in an Array

Problem: Write a program in C to find the largest and smallest element in an array.

13. Find the Second Largest Element in an Array

Problem: Write a program in C to find the second largest element in an array without sorting.

14. Rotate an Array by One Position

Problem: Write a program in C to rotate the array by one position towards the right.

15. Check If an Array is Palindromic

Problem: Write a program in C to check if an array reads the same forward and backward.

Practicing these C programming array exercises will strengthen your logical thinking and problem-solving skills. If you’re preparing for coding interviews or competitive programming, these problems will be a great way to improve your expertise in array manipulation.

Happy Coding! 🎯

Leave a Comment

Your email address will not be published. Required fields are marked *