C array examples

C Array Programs

Practice 58 C array programs organized by basic operations, manipulation, comparisons, sorting, rotation, problem solving, and matrices.

Practice library

58

array programs

Learn arrays step by step

An array stores multiple elements of the same data type in contiguous memory locations.

Array indexing in C starts at 0 and ends at N-1. Work through the categories in order to build from basic traversal to matrix operations.

Programs 1-18

Basic Array Operations

  1. 01C Program to read and print elements of array
  2. 02C Program to print all elements of an array in reverse order
  3. 03C Program to print sum of array elements
  4. 04C Program to find the average of all elements in an array
  5. 05C Program to find the largest element in an array
  6. 06C Program to find the smallest element in an array
  7. 07C Program to print maximum and minimum element in array
  8. 08C Program to count the number of elements in an array
  9. 09C Program to count even and odd numbers in an array
  10. 10C Program to print only even numbers from an array
  11. 11C Program to print only odd numbers from an array
  12. 12C Program to count positive, negative and zero numbers in array
  13. 13C Program to find the sum of all even numbers in an array
  14. 14C Program to find the sum of all odd numbers in an array
  15. 15C program to search an element in an array
  16. 16C Program to find the index of a given number in an array
  17. 17C Program to copy all array elements from one array to another
  18. 18C Program to swap the first and last elements of an array

Programs 19-30

Basic Array Manipulation

  1. 19C program to find reverse of an array
  2. 20C program to merge two arrays into a third array
  3. 21C Program to insert an element in array
  4. 22C Program to delete an element from array
  5. 23C Program to count occurrences of a given number in an array
  6. 24C Program to print the frequency of each element in an array
  7. 25C Program to find all unique elements in an array
  8. 26C Program to count duplicate elements in an array
  9. 27C Program to print duplicate elements in an array
  10. 28C Program to delete duplicate elements from an array
  11. 29C Program to find the first duplicate element in an array
  12. 30C Program to find the first non-repeating element in an array

Programs 31-36

Minimum, Maximum & Comparison Problems

  1. 31C Program to print the second largest element in an array
  2. 32C Program to find the second smallest element in an array
  3. 33C Program to find the third largest element without sorting
  4. 34C Program to find the difference between the largest and smallest elements
  5. 35C Program to find the most frequent element in an array
  6. 36C Program to find the least frequent element in an array

Programs 37-40

Two Array Problems

  1. 37C Program to find common elements between two arrays
  2. 38C Program to find elements in the first array but not the second
  3. 39C Program to check whether two arrays are equal
  4. 40C Program to combine two arrays without duplicates

Programs 41-42

Sorting

  1. 41C program to sort an array
  2. 42C Program to check whether an array is sorted in ascending order

Programs 43-47

Array Movement & Rotation

  1. 43C Program to move all zeros to the end of an array
  2. 44C Program to move all zeros to the beginning of an array
  3. 45C Program to move even numbers to the beginning and odd numbers to the end
  4. 46C program to left rotate an array
  5. 47C program to right rotate an array

Programs 48-53

Array Problem Solving

  1. 48C Program to check whether an array is a palindrome
  2. 49C Program to find the missing number from a sequence
  3. 50C Program to find multiple missing numbers from a sequence
  4. 51C Program to find all pairs with a given target sum
  5. 52C Program to find all triplets with a given target sum
  6. 53C Program to find the longest consecutive sequence of equal numbers

Programs 54-58

2D Arrays / Matrices

  1. 54C Program to read and print elements of a matrix
  2. 55C Program to find the sum of all elements in a matrix
  3. 56C program to add two matrices
  4. 57C program to perform scalar matrix multiplication
  5. 58C Program to multiply two matrices