Posts

Showing posts from November, 2019

Code for BUBBLE Sort

Image
1                                                      Bubble sort Ø        #include<stdio.h> #include<conio.h> void BubbleSort(int[] , int); void main() {    int array[10], n, i;    clrscr();    printf("\n\n------------------------ BUBBLE SORT -----------------------");    printf("\n\n ENTER NUMBER OF ELEMENTS : ");    scanf("%d", &n);    printf("\n");    for (i = 0 ; i < n ; i++ )    { printf("ENTER ELEMENT %d: ",i+1);      scanf("%d", &array[i]);    }    BubbleSort(array,n);    getch(); } void BubbleSort(int array[], int n) {    int i,c,j,temp;    for ( i = 0 ; i < ( n-1 ) ; i++ )    {       for ( j = 0 ; j < n-i-1 ; j++ )       {        if ( array[j] > array[j+1])        {                 temp = array[j];                 array[j] = array[j+1];                 array[j+1] = temp;        }       }       pr

Code for SELECTION Sort in C-Programming

Image
1                               Selection Sort Ø       #include<stdio.h> #include<conio.h> void SelectionSort(int[] , int); void main() {    int array[10], n, i;    clrscr();    printf("\n\n--------------------- SELECTION SORT --------------------");    printf("\n\n ENTER NUMBER OF ELEMENTS : ");    scanf("%d", &n);    printf("\n");    for (i = 0 ; i < n ; i++ )    { printf("ENTER ELEMENT %d : ",i+1);     scanf("%d", &array[i]);      }    SelectionSort(array,n);    getch(); } void SelectionSort(int array[], int n) {    int i,c,       j,temp;    for ( i = 0 ; i < ( n-1 ) ; i++ )    {       for ( j = i + 1 ; j < n ; j++ )       {            if ( array[i] > array[j])              {                 temp = array[i];                 array[i] = array[j];                 array[j] = temp;               }       }