Tag Archives: user-defined functions

C Program to Search for an Element in an Array Using Binary Search

There is a condition for performing binary search, the prerequisite for binary search is that the array should be sorted. Firstly we compare the item to be search with the middle element of the array, if the the item is found the search is successful otherwise the array is divided into two halves, first half contains all the elements to the left of the middle element and the other one consists of all the elements to the right side of the middle element. Since the array is sorted, all the element in the left half will be smaller than the middle element and greater than the middle element in the right half. If the item to be search is less than the middle element, it will be search in left half otherwise it will be search in the right half (if it is greater then the middle element). Let’s now see the c program to search for an element in an array using binary search.

C Program ►►
Continue reading C Program to Search for an Element in an Array Using Binary Search

C Program to Search an Element in an Array Using Linear or Sequential Search

Before making the C program to search an element in an array using linear search, first understand what linear search means. Sequential search or Linear search is performed in linear way i.e. it starts from the beginning of the list and continues till we find the item or reach the end of list. The item to be searched is compared with each element of the list one by one, starting from the first element.

Let’s See The Program ►►
Continue reading C Program to Search an Element in an Array Using Linear or Sequential Search

C Program to Calculate Sum using only One Variable

As we also talked before that the less numbers of variables in the program means less memory used by the program and in return the program also run faster. So it;s always best to reduce the number of variables used in the program, as to increase the execution time of the program.

In this post we are going to make the program to calculate sum of two integers using only a single variable. We will achieve this by making a function.

Let’s have ah Look The Program ►► Continue reading C Program to Calculate Sum using only One Variable

C Program to Compare Two Strings Through User-Defined Function

Strings are another good feature of C. They provide a great way to store characters, not in really, in actual C Program stores the ASCII Values of characters that’s why there is no any non-numeric data-type in C. All in hidden, access and manipulate through numeric values. In other words, Strings are arrays of characters.  

There are many functions for strings and to compare two strings there is also strcmp(str1,str2); function. Which if the two strings are equal gives the value 0(zero) and otherwise return the ASCII value difference between first non-matching characters.

Lets do it with some trick to eliminate the variables and shorten the size of the program.

Lets Do It with the User-define Program ►► Continue reading C Program to Compare Two Strings Through User-Defined Function