C Implementation of Selection Sort and Search Algorithms

Selection Sort Algorithm in C

Selection Sort is a simple sorting algorithm that repeatedly finds the minimum element from the unsorted part of the array and swaps it with the element at the current position.

C Implementation of Selection Sort Function

#include <stdio.h>

The function void selectionSort(int arr[], int n) performs the sorting:

void selectionSort(int arr[], int n)

{

int i, j, minIndex, temp;

for (i = 0; i < n - 1; i++) {

minIndex = i;

// Find the index of the minimum element in the unsorted

Read More

C Programming Fundamentals: Arrays, Functions, and Search Algorithms

Array Initialization Methods in C

Arrays in C can be initialized in two main ways:

1. Compile-Time Initialization

Values are assigned at the time of declaration.

int arr[5] = {1, 2, 3, 4, 5};

If fewer values are provided than the array size, the unused elements are automatically initialized to 0:

int arr[5] = {1, 2}; // arr = {1, 2, 0, 0, 0}

2. Run-Time Initialization

Values are entered during execution using input functions like scanf().

int arr[5], i;
for(i = 0; i < 5; i++) {
    scanf("%d", &
Read More