All posts by Ushaib Usmani

A boy who amazed by the power of World Wide Web. And a full time learner programmer who wants to share everything he got to know.

C Program to Sort an Array Using Insertion Sort

Sorting is a procedure in which the given elements are arranged in ascending or descending order. For example if the elements of an array are –

5, 11, 15, 8, 7, 54, 63, 44

After sorting these elements in ascending order, the elements would be –

5, 7, 8, 11, 15, 44, 54, 63

What is Insertion Sort is :

Insertion sort proceeds by inserting each element at the proper place in a sorted list. This is the same technique used by card players for arranging cards. When they receive a card, they place it in the appropriate place among the cards that they have already arranged.

We will consider our list to be divided into two parts – sorted and unsorted. Initially the sorted part contains only the first element of the list and unsorted part contains the rest of the elements. In each pass, the first element from the unsorted part is taken and inserted into the sorted part at appropriate place. If there are n elements in the list, then after n-1 passes the unsorted part disappears and our whole list becomes sorted. Let’s see the c program to sort an array using insertion sort.

C Program ►►
Continue reading C Program to Sort an Array Using Insertion Sort

C Program to Sort an Array Using Selection Sort

Sorting is a procedure in which the given elements are arranged in ascending or descending order. For example if the elements of an array are –

5, 11, 15, 8, 7, 54, 63, 44

After sorting these elements in ascending order, the elements would be –

5, 7, 8, 11, 15, 44, 54, 63

What is Selection Sort is :

Suppose that you are given some numbers and asked to arrange them is ascending order. The most intuitive way to do this would be to find the smallest number and put it in the first place and then find the second smallest number and put it in the second place and so on. This is the simple technique on which selection sort is based. It is named so because in each pass it selects the smallest element and keeps it in its exact place. Let’s now see the c program to sort an array using selection sort.

C Program ►►
Continue reading C Program to Sort an Array Using Selection Sort

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

Best Way to Learn C Programming Language

Learning a language is not so difficult. The only thing this needs is your full concentration and passion about coding. You must first set your mind and start taking interest in the coding. And then it will be all fun to learn any programming language.

You all must be aware of the fact that the first step towards learning something new involves finding out the best possible way in which to begin. This can be quite a difficult and time consuming task and often becomes the deciding factor with regards to whether or not you continue with your pursuit. Continue reading Best Way to Learn C Programming Language

C Program to Sort an Array Using Bubble Sort

Sorting is a procedure in which the given elements are arranged in ascending or descending order. For example if the elements of an array are –

5, 11, 15, 8, 7, 54, 63, 44

After sorting these elements in ascending order, the elements would be –

5, 7, 8, 11, 15, 44, 54, 63

What is Bubble Sort is :

Bubble sort proceeds by scanning the list and exchanging the adjacent elements if they are out of order with respect to each other. It compares each element with its adjacent element and swaps them if they are not in order i.e. arr[j] will be compared with arr[j+1] and if arr[j]>arr[j+1] then they will be swapped.

Let’s See the Program for Bubble Sort ►► Continue reading C Program to Sort an Array Using Bubble Sort

C Program to Find Whether the Number is Even or Odd

We all know, the number which can divide from 2 completely, means if the reminder is zero, then the number is even and which cannot are odd numbers.

The same we will do in our program to know whether the number, which is input through the keyboard, is even or odd.

Remember the modulus operator (%), this operator returns the reminder, when dividing any number. So we will condition the if statement, if the reminder is zero after diving the number by 2, then the number is even otherwise odd.

Let’s have ah Look The Program ►► Continue reading C Program to Find Whether the Number is Even or Odd