Here we’ll write a C function to merge two sorted arrays into one. The merged array will also be sorted. Here we’ll use two sorted integer arrays that are sorted in ascending order. After merging the result array will contain all the numbers from the original arrays and will be sorted in ascending order. The … Continue reading “C Program to Merge Two Sorted Arrays into one Sorted Array”
Category: C
C Program to Find the Sum of all Digits of a Number
Here we’ll see how to write a C program to find the summation of all digits in a number. For example, the sum of the digits of 43652 is 20 (4+3+6+5+2) The sum_digits() function returns sum of all digits of the input number n. It has a loop. In every iteration it gets the last … Continue reading “C Program to Find the Sum of all Digits of a Number”
C Program to Search for an Element in Linked List
Here we’ll see how to write a C program to find an element in a linked list. The function is_present() takes a linked list (head pointer) and a value (val) as input arguments. If the value (val) is present in any of the nodes, this function returns the pointer of that node. Otherwise it returns … Continue reading “C Program to Search for an Element in Linked List”
C Program to Print the Length of a Linked List
Here we’ll see how to write a C program to print the length of a linked list. The function get_length() takes a linked list as input and returns the length of it. First we’ll create a linked list and pass that list to the get_length() function to print the length of the list. The get_length() … Continue reading “C Program to Print the Length of a Linked List”
C Program to Check Whether Two Linked Lists are Equal
Here we’ll see how to write a C program to compare two linked lists. First we’ll create three linked lists, first two are equal and third one is different. We’ll compare these linked lists using the check_equal() function. The check_equal() function traverses the linked lists until at least one of them reaches to NULL (end). … Continue reading “C Program to Check Whether Two Linked Lists are Equal”