­
­

Shell Sort

By Developgram - December 12, 2016
/* Summary: Shell Sort generalizes an exchanging sort, such as insertion or bubble sort, by starting the comparison and exchange of elements with elements that are far apart before finishing with neighboring elements. Starting with far apart elements can move some out-of-place elements into position faster than a simple nearest neighbor exchange.The idea is to arrange the list of elements so that, starting...

Continue Reading

  • Share:

Selection Sort

By Developgram - December 12, 2016
/* Summary: Selection sort divides the input list into two parts: the sublist of items already sorted and the sublist of items remaining to be sorted. It proceeds by finding the smallest (or largest) element in the unsorted sublist, exchanging it with the leftmost unsorted element and moving the sublist boundaries one element to the right. Complexity - O(n^2) */ #include<conio.h> #include<stdio.h> #define...

Continue Reading

  • Share:

Radix Sort

By Developgram - December 12, 2016
/* Summary: Radix sort is a non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual digits which share the same significant position and value. Two classifications of radix sorts are least significant digit (LSD) radix sorts and most significant digit (MSD) radix sorts. LSD radix sorts process the integer representations starting from the least digit and...

Continue Reading

  • Share:

Quick Sort

By Developgram - December 12, 2016
/* Summary: Quicksort is a very efficient sorting algorithm.It has two phases: -the partition phase and -the sort phase. Most of the work is done in the partition phase - it works out where to divide the work. The sort phase simply sorts the two smaller problems that are generated in the partition phase. Complexity: O(n·log n) */ #include <stdio.h> int quicksort (int...

Continue Reading

  • Share:

Merge Sort

By Developgram - December 12, 2016
/* Summary: Merge sort is a divide and conquer comparison-based sorting algorithm. It works as follows:- 1. Divide the unsorted list into n sublists, each containing 1 element (a list of 1 element is considered sorted). 2. Repeatedly merge sublists to produce new sublists until there is only 1 sublist remaining. This will be the sorted list. Complexity - O(n·log n) */ #include...

Continue Reading

  • Share:

Insertion Sort

By Developgram - December 12, 2016
/* Summary: Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain. Complexity - O(n^2) */ #include <stdio.h> #define MAX 10 int insertion_sort(int *); int main() {...

Continue Reading

  • Share:

Heap Sort

By Developgram - December 12, 2016
/* Summary: The heapsort algorithm can be divided into two parts. -Step 1: a heap is built out of the data. -Step 2: a sorted array is created by repeatedly removing the largest element from the heap, and inserting it into the array. The heap is reconstructed after each removal. Once all objects have been removed from the heap, we have a sorted...

Continue Reading

  • Share:

Gnome Sort

By Developgram - December 12, 2016
/* Summary: Gnome sort(stupid sort) is a sorting algorithm which is similar to insertion sort, except that moving an element to its proper place is accomplished by a series of swaps, as in bubble sort. It is conceptually simple, requiring no nested loops. Complexity - O(n^2) */ #include <stdio.h> int main() { int i, temp, ar[10], n; printf("\nenter the elements number u would...

Continue Reading

  • Share:

Cocktail Sort

By Developgram - December 12, 2016
/* Summary: Cocktail sort is a variation of bubble sort that is both a stable sorting algorithm and a comparison sort. The algorithm differs from a bubble sort in that it sorts in both directions on each pass through the list. This sorting algorithm is only marginally more difficult to implement than a bubble sort, and solves the problem of turtles in bubble...

Continue Reading

  • Share:

Bubble Sort

By Developgram - December 12, 2016
/* Summary: Bubble sort is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. Complexity - O(n^2) */ #include <stdio.h> #define MAXSIZE 10 int main() { int array[MAXSIZE]; int i, j, num, temp; printf("Enter the value of num \n"); scanf("%d", &num);...

Continue Reading

  • Share:

Alphabetical Sort

By Developgram - December 12, 2016
/* Summary: Alphabetical sort is a program whereby strings of characters are placed in order based on the position of the characters in the conventional ordering of an alphabet. */ #include <stdio.h> #include <string.h> #include <conio.h> int main() { char name[10][8], tname[10][8], temp[8]; int i, j, n; printf("Enter the value of n \n"); scanf("%d", &n); printf("Enter %d names ", n); for (i =...

Continue Reading

  • Share:

Binary Search

By Developgram - December 12, 2016
/* Summary: Binary search compares the search value with the value of the middle element of the array. If they match, then a matching element has been found and its position is returned. Otherwise, if the search value is less than the middle element's value, then the algorithm repeats its action on the sub-array to the left of the middle element or, if...

Continue Reading

  • Share:

Linear Search

By Developgram - December 12, 2016
/* Summary: Linear search or sequential search is a method for finding a particular value in a list, that consists of checking every one of its elements, one at a time and in sequence, until the desired one is found. Complexity - O(n) */ #include <stdio.h> int main() { int array[10]; int i, num, keynum, found = 0; printf("Enter the value of num...

Continue Reading

  • Share:

Even Odd

By Developgram - December 12, 2016
/* Summary: Check whether a number entered by user is even or odd. */ #include <stdio.h> int main() { int num; printf("Enter an integer you want to check: "); scanf("%d",&num); /* Checking whether remainder is 0 or not. */ if((num%2)==0) printf("%d is even.",num); else printf("%d is odd.",num); return 0; } ...

Continue Reading

  • Share:

Swap Numbers

By Developgram - December 12, 2016
/* Summary: Swap two numbers without using third number. */ #include <stdio.h> int main() { int a,b; printf("Enter a and b"); scanf("%d",&a); scanf("%d",&b); printf("Before Swapping a=%d,b=%d",a,b); a=a+b; b=a-b; a=a-b; printf("After Swapping a=%d,b=%d",a,b); return 0; } ...

Continue Reading

  • Share:

Simple Calculator

By Developgram - December 12, 2016
/* Summary: Does addition subtraction multiplication division */ # include <stdio.h> int main() { char operator; float num1,num2; printf("Enter operator either + or - or * or / : "); scanf("%c",&operator); printf("Enter two operands: "); scanf("%f%f",&num1,&num2); switch(operator) { case '+': printf("num1+num2=%.2f",num1+num2); break; case '-': printf("num1-num2=%.2f",num1-num2); break; case '*': printf("num1*num2=%.2f",num1*num2); break; case '/': printf("num2/num1 = %.2f",num1/num2); break; default: /* If operator is other than...

Continue Reading

  • Share:

Square Root

By Developgram - December 12, 2016
/* Summary: Finds roots of a quadratic equation ax2+bx+c=0 where a, b and c are coefficients. This program will ask the coefficients: a, b and c from user and displays the roots. */ #include <stdio.h> #include <math.h> int main() { float a, b, c, determinant, r1,r2, real, imag; printf("Enter coefficients a, b and c: "); scanf("%f%f%f",&a,&b,&c); determinant=b*b-4*a*c; if (determinant>0) { r1= (-b+sqrt(determinant))/(2*a); r2=...

Continue Reading

  • Share:

Temperature Converter

By Developgram - December 12, 2016
/* Summary: Converts temperature from fahrenheit to degree celcius */ #include <stdio.h> int main () { int fahrenheit; double celsius; printf("Enter the temperature in degrees fahrenheit:"); scanf("%d", &fahrenheit); celsius = (5.0/9.0) * (fahrenheit-32); printf ("The converted temperature is %lf\n", celsius); return 0; } ...

Continue Reading

  • Share: