0% found this document useful (0 votes)
6 views2 pages

Aoa 1

The document contains two C programs that implement sorting algorithms: Selection Sort and Insertion Sort. Each program prompts the user to enter a number of elements and then sorts them while displaying the array after each pass. The final sorted array is printed at the end of each program.

Uploaded by

556-Harsh Tandel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Aoa 1

The document contains two C programs that implement sorting algorithms: Selection Sort and Insertion Sort. Each program prompts the user to enter a number of elements and then sorts them while displaying the array after each pass. The final sorted array is printed at the end of each program.

Uploaded by

556-Harsh Tandel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

AOA -1 CLASS/SECTION:SE CPMN C3

NAME: SMITH LOPES ROLLNO:46

SELECTION SORT
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int k, num, i, j, temp, min_index;
int ele[50];
printf("Enter Number of Elements: ");
scanf("%d", &num);
printf("Enter Elements: ");

for (i = 0; i < num; i++) {


scanf("%d", &ele[i]);
}
for (i = 0; i < num - 1; i++) {
printf("Pass %d: ", i + 1);
min_index = i;

for (j = i + 1; j < num; j++) {


if (ele[j] < ele[min_index]) {
min_index = j;
}
}
if (min_index != i) {
temp = ele[i];
ele[i] = ele[min_index];
ele[min_index] = temp;
}
for (k = 0; k < num; k++) {
printf("%d ", ele[k]);
}
printf("\n");
}
printf("Sorted Array: ");
for (i = 0; i < num; i++) {
printf("%d ", ele[i]);
}
getch();
}
AOA -1 CLASS/SECTION:SE CPMN C3
NAME: SMITH LOPES ROLLNO:46

INSERTION SORT
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int k, num, i, j, key;
int ele[50];

printf("Enter Number of Elements: ");


scanf("%d", &num);
printf("Enter Elements: ");

for (i = 0; i < num; i++) {


scanf("%d", &ele[i]);
}

for (i = 1; i < num; i++) {


key = ele[i];
j = i - 1;

while (j >= 0 && ele[j] > key) {


ele[j + 1] = ele[j];
j--;
}
ele[j + 1] = key;

printf("Pass %d: ", i);


for (k = 0; k < num; k++) {
printf("%d ", ele[k]);
}
printf("\n");
}
printf("Sorted Array: ");
for (i = 0; i < num; i++) {
printf("%d ", ele[i]);
}
getch();
}

You might also like