Insertion Sort using C programing
Code With Rudy
#include <stdio.h> void main() { int array[100], c, j, n, temp; printf("Enter number of elements: "); scanf("%d", &n); printf("Enter %d elements: ", n); for (c = 0; c < n; c++) { scanf("%d", &array[c]); } for (c = 1; c < n; c++) { temp = array[c]; j = c - 1; while (j >= 0 && array[j] > temp) { array[j + 1] = array[j]; j--; } array[j + 1] = temp; } printf("Sorted elements: "); for (c = 0; c < n; c++) { printf("%d ", array[c]); } printf("\n"); }
0 Comments