C Programming Examples on Arrays

C programming examples

This section covers C programming examples on Arrays. Every example program includes the description of the program, C code as well as output of the program. All examples are compiled and tested on a Linux system. These examples can be simple C programs or advanced C programs. So, they are suitable for any user (dummies, beginners or advanced users).

Here is the listing of C programming examples on Arrays.

1. C Examples on Mathematical Operations on an Array

An array is a sequence of data items of homogeneous value. The C programs in this section illustrates the addition operation being performed on an array. The addition operation is combined with different aspects like using pointers, using pointers as arguments, using Malloc and computing the sum of contiguous Subarray within a 1-D array of numbers which has the largest sum.

C Program to Calculate Sum & Average of an Array
C Program to Calculate the Sum of the Array Elements using Pointer
C Program to Calculate Sum of all Elements of an Array using Pointers as Arguments
C Program to Compute the Sum of two One-Dimensional Arrays using Malloc
C Program to Find the Sum of Contiguous Subarray within a 1 – D Array of Numbers which has the Largest Sum

2. C Examples on Finding the Largest and Smallest Numbers in an Array

The C programs in this section evaluate the largest of the given numbers in an array, two of the largest numbers in a given array and second largest and smallest elements in an array.

advertisement
C Program to Find the Largest Two Numbers in a given Array
C Program to Find the Second Largest & Smallest Elements in an Array
C Program to Find the Largest Number in an Array

3. C Examples on Inserting and Deleting Elements to and from an Array

The C programs in this section deals with insertion and deletion of elements in an array. It has programs to insert even and odd elements of an array into two separate arrays, to insert an element in a specified position in a given array, to remove the specified integer from an array and to cyclically permute the elements of the given array.

C Program to Put Even & Odd Elements of an Array in 2 Separate Arrays
C Program to Insert an Element in a Specified Position in a given Array
C Program to Delete the Specified Integer from an Array
C Program to Cyclically Permute the Elements of an Array

4. C Examples on Sort and Merge Operations on an Array

The C programs in this section deals with Sorting and Merging operations on an array. It has programs that demonstrate sorting of an array in ascending and descending order, sorting the names in alphabetical order, merging and sorting elements of two different arrays, merging the elements of 2 sorted arrays, sorting the numbers using Bubble Sort, splitting an array from the specified position and adding the first part to the end and a program to accept an array and perform the swapping operation on the elements using pointers.

C Program to Sort the Array in an Ascending Order
C Program to Sort the Array in Descending Order
C Program to Sort Names in an Alphabetical Order
C Program to Merge and Sort Elements of 2 different Arrays
C Program to Merge the Elements of 2 Sorted Array
C Program to Sort N Numbers in Ascending Order using Bubble Sort
C Program to Split an Array from Specified Position & Add First Part to the End
C Program to Accept an Array & Swap Elements using Pointers

5. C Examples on Search Operation on an Array

The C programs in this section deals with the search operations on an array. It has programs to read an array and search for an element in the input array, perform Binary Search on the elements of an array and to find the biggest number in an array of given numbers using recursion.

advertisement
C Program to Read an Array and Search for an Element
C Program to accept Sorted Array and do Search using Binary Search
C Program to find the Biggest Number in an Array of Numbers using Recursion

6. C Examples on Queue and Stack Implementation of an Array

The C programs in this section deals with implementation of Queues and Stacks using an array. The programs also check for Overflow and Underflow conditions respectively.

C Program to Implement a Queue using an Array
C Program to Implement two Stacks using a Single Array & Check for Overflow & Underflow

7. C Examples on Printing the Elements of an Array

The C programs in this section deals with programs to generate Pascal Triangle, printing the number of odd and even numbers in an array, printing all the repeated numbers with frequency in an array and printing the kth element in an array.

C Program to Generate Pascal Triangle 1 D Array
C Program to Print the Number of Odd & Even Numbers in an Array
C Program to Print All the Repeated Numbers with Frequency in an Array
C Program to Print the kth Element in the Array

8. C Examples on Operations on Individual Elements of an Array

The C programs in this section deals with the individual elements of an array. It has programs to find the number of elements in the given array, testing array bounds while inserting elements into an array, printing the alternate elements, finding the odd elements of an array, incrementing the elements of an array and printing them, finding the missing elements and non-repeating elements in an array, segregating 0s and 1s on the left and the right side of an array and finding the 2 elements of an array such that the difference between them is the largest.

advertisement
C Program to Find the Number of Elements in an Array
C Program to Check Array bounds while Inputing Elements into the Array
C Program to Print the Alternate Elements in an Array
C Program to Find the Odd Element given an Array with only two Different Element
C Program to Increment Every Element of the Array by One & Print Incremented Array
C Program to Find the Number of Non Repeated Elements in an Array
C Program to identify missing Numbers in a given Array
C Program to Segregate 0s on Left Side & 1s on right side of the Array
C Program to Find 2 Elements in the Array such that Difference between them is Largest

9. C Examples on Mathematical Functions and their Applications on Arrays

The C programs in this section deals with various aspects of mathematical functions and their applications on Arrays. It has programs to input a string and store the respective ASCII values in an integer array and thereby print the resultant array. It has programs on mathematical and statistical functions like Floor and Ceiling functions, Summation function, Union and Intersection operations, Median function, computing the Squares of the elements and testing if the given integer X appears more than N/2 times in a sorted array of N integers.

C Program to Input a String & Store their Ascii Values in an Integer Array & Print the Array
C Program to Input an Array, Store the Squares of these Elements in an Array & Print it
C Program to Find the two Elements such that their Sum is Closest to Zero
C Program to Find if a given Integer X appears more than N/2 times in a Sorted Array of N Integers
C Program to Find the Median of the Elements after Merging these 2 Sorted Arrays with Same Size
C Program to Find Union & Intersection of 2 Arrays
C Program to Find Ceiling & Floor of X given a Sorted Array & a value X
C Program to Find the Summation of Node values at Row or Level

advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn