Practice 50 C# Array Programming Questions
Q1. Write a C# program to find the largest element in an array.
Input: arr = [3, 1, 4, 1, 5]
Output: Largest element = 5
Q2. Write a C# program to find the smallest element in an array.
Input: arr = [3, 1, 4, 1, 5]
Output: Smallest element = 1
Q3. Write a C# program to find the sum of all elements in an array.
Input: arr = [1, 2, 3, 4]
Output: Sum = 10
Q4. Write a C# program to calculate the average of all elements in an array.
Input: arr = [1, 2, 3, 4, 5]
Output: Average = 3.0
Q5. Write a C# program to count the number of even numbers in an array.
Input: arr = [1, 2, 3, 4, 5]
Output: Even count = 2
Q6. Write a C# program to count the number of odd numbers in an array.
Input: arr = [1, 2, 3, 4, 5]
Output: Odd count = 3
Q7. Write a C# program to find the second largest element in an array.
Input: arr = [3, 1, 4, 5, 6]
Output: Second largest element = 5
Q8. Write a C# program to reverse an array.
Input: arr = [1, 2, 3, 4]
Output: Reversed array = [4, 3, 2, 1]
Q9. Write a C# program to find the frequency of a given element in an array.
Input: arr = [1, 2, 2, 3, 2], element = 2
Output: Frequency of 2 = 3
Q10. Write a C# program to check if an array contains a specific element.
Input: arr = [1, 2, 3, 4], element = 3
Output: Element found
Q11. Write a C# program to find the common elements between two arrays.
Input: arr1 = [1, 2, 3, 4], arr2 = [3, 4, 5, 6]
Output: Common elements = 3 4
Q12. Write a C# program to sort an array in ascending order.
Input: arr = [5, 3, 1, 4, 2]
Output: Sorted array = [1, 2, 3, 4, 5]
Q13. Write a C# program to sort an array in descending order.
Input: arr = [5, 3, 1, 4, 2]
Output: Sorted array = [5, 4, 3, 2, 1]
Q14. Write a C# program to find the sum of odd numbers in an array.
Input: arr = [1, 2, 3, 4, 5]
Output: Sum of odd numbers = 9
Q15. Write a C# program to find the sum of even numbers in an array.
Input: arr = [1, 2, 3, 4, 5]
Output: Sum of even numbers = 6
Q16. Write a C# program to remove duplicates from an array.
Input: arr = [1, 2, 2, 3, 4, 4]
Output: Array without duplicates = [1, 2, 3, 4]
Q17. Write a C# program to merge two arrays into one.
Input: arr1 = [1, 2, 3], arr2 = [4, 5, 6]
Output: Merged array = [1, 2, 3, 4, 5, 6]
Q18. Write a C# program to find the maximum product of two elements in an array.
Input: arr = [1, 2, 3, 4]
Output: Maximum product = 12
Q19. Write a C# program to check if an array is sorted in ascending order.
Input: arr = [1, 2, 3, 4]
Output: Array is sorted
Q20. Write a C# program to check if an array is sorted in descending order.
Input: arr = [4, 3, 2, 1]
Output: Array is sorted
Q21. Write a C# program to find the first non-repeated element in an array.
Input: arr = [1, 2, 2, 3, 4, 4]
Output: First non-repeated element = 1
Q22. Write a C# program to check if two arrays are equal.
Input: arr1 = [1, 2, 3], arr2 = [1, 2, 3]
Output: Arrays are equal
Q23. Write a C# program to rotate an array by one position to the left.
Input: arr = [1, 2, 3, 4]
Output: Rotated array = [2, 3, 4, 1]
Q24. Write a C# program to rotate an array by one position to the right.
Input: arr = [1, 2, 3, 4]
Output: Rotated array = [4, 1, 2, 3]
Q25. Write a C# program to find the intersection of two arrays.
Input: arr1 = [1, 2, 3, 4], arr2 = [3, 4, 5, 6]
Output: Intersection = [3, 4]
Q26. Write a C# program to find the union of two arrays.
Input: arr1 = [1, 2, 3], arr2 = [3, 4, 5]
Output: Union = [1, 2, 3, 4, 5]
Q27. Write a C# program to find the difference between two arrays.
Input: arr1 = [1, 2, 3], arr2 = [2, 3, 4]
Output: Difference = [1]
Q28. Write a C# program to copy all elements of one array to another array.
Input: arr1 = [1, 2, 3, 4]
Output: arr2 = [1, 2, 3, 4]
Q29. Write a C# program to find the largest sum of any subarray in an array.
Input: arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output: Largest sum = 6
Q30. Write a C# program to check if an array contains only positive numbers.
Input: arr = [1, 2, 3, 4]
Output: Array contains only positive numbers
Q31. Write a C# program to find the minimum sum of any subarray in an array.
Input: arr = [1, 2, 3, -1, -2]
Output: Minimum sum = -3
Q32. Write a C# program to find the largest even number in an array.
Input: arr = [1, 2, 3, 4, 5]
Output: Largest even number = 4
Q33. Write a C# program to replace all negative numbers in an array with zero.
Input: arr = [-1, 2, -3, 4, -5]
Output: Modified array = [0, 2, 0, 4, 0]
Q34. Write a C# program to print all the unique elements in an array.
Input: arr = [1, 2, 2, 3, 4]
Output: Unique elements = 1 3 4
Q35. Write a C# program to find the most frequent element in an array.
Input: arr = [1, 2, 2, 3, 3, 3]
Output: Most frequent element = 3
Q36. Write a C# program to find the sum of positive numbers in an array.
Input: arr = [-1, 2, 3, -4, 5]
Output: Sum of positive numbers = 10
Q37. Write a C# program to check if an array contains only odd numbers.
Input: arr = [1, 3, 5]
Output: Array contains only odd numbers
Q38. Write a C# program to find the product of all elements in an array.
Input: arr = [1, 2, 3, 4]
Output: Product = 24
Q39. Write a C# program to find the first duplicate element in an array.
Input: arr = [1, 2, 3, 1, 4]
Output: First duplicate = 1
Q40. Write a C# program to remove a specific element from an array.
Input: arr = [1, 2, 3, 4], element = 3
Output: Array after removal = [1, 2, 4]
Q41. Write a C# program to find the difference between the largest and smallest element in an array.
Input: arr = [5, 2, 9, 1, 3]
Output: Difference = 8
Q42. Write a C# program to check if an array contains only even numbers.
Input: arr = [2, 4, 6, 8]
Output: Array contains only even numbers
Q43. Write a C# program to print the elements of an array in reverse order.
Input: arr = [1, 2, 3, 4]
Output: Reversed array = [4, 3, 2, 1]
Q44. Write a C# program to remove all even numbers from an array.
Input: arr = [1, 2, 3, 4, 5]
Output: Array after removing evens = [1, 3, 5]
Q45. Write a C# program to count the total number of elements in an array.
Input: arr = [1, 2, 3, 4, 5]
Output: Total count = 5
Q46. Write a C# program to find the median of an array.
Input: arr = [1, 3, 2]
Output: Median = 2
Q47. Write a C# program to find the mode (most frequent element) in an array.
Input: arr = [1, 2, 3, 3, 4]
Output: Mode = 3
Q48. Write a C# program to shift all zeros to the end of an array.
Input: arr = [1, 0, 2, 0, 3]
Output: Array after shifting zeros = [1, 2, 3, 0, 0]
Q49. Write a C# program to find the index of an element in an array.
Input: arr = [1, 2, 3, 4], element = 3
Output: Index of element = 2
Q50. Write a C# program to swap two elements in an array.
Input: arr = [1, 2, 3, 4], index1 = 0, index2 = 2
Output: Array after swapping = [3, 2, 1, 4]
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!