0% found this document useful (0 votes)
8 views3 pages

2

CodeTantra Solution Programme 2

Uploaded by

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

2

CodeTantra Solution Programme 2

Uploaded by

devraikunal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 3
SNo:2 EXP. Name: Write aC program to Sort the elements using Insertion Sort . Technique im: Date:2023-10-03 Write a program to sort the given elements using Insertion sort technique ( Ascending order ), Source Code: (racine | Hincludecstdio.h> void main() { int a[20], 4, n, J, temps printé("n ="); scanf("Rd", &n)3 // Wieite the for loop to read array elements for(i = @s4cnsit+)( print#("a[")5 printf("%d",4); printf( scanf("%d",8a[1])5 i) printf("Before sorting : \n"); // Wirite the for loop to display array elenents before sorting For(1 = @s4cnsit+){ printf("a[")5 print#("%d", 4); printf("] ="); print®("%d\n",a4])5 > //kirite the code to sort elenents for(i = Lsicnsit+){ temp = ali]; j=is while(j>=088a[4j]>temp){ a(j+1] = ali]s ged + a[J+1] = temp; > printf("After sorting : \n"); // veite the for loop to display array elenents after sorting For(i=0;Lensi++){ print#( print ("%a" printé( printé("%d\n",a[1]); Execution Results - 1 test cases have succeeded! Page No: 1 ib: 2200331540075 2022-2026-CSE-0S-8 stitute Of Technology Raj Kumar Goel Test Case - 1 (User Output h= 5 [el = 22, bay = 4 [2] = 27 B) = 37, lta) = 42 before sorting + [e] = 32 af2] = 4 lz] = 27 [31 = 37, al4] = 42 hafter sorting + [el] = 4 (2) = 12 (2) = 27 [3] = 37 [4] = at Test Case -2 (User Output h=7 (eo) = 3 alt] = 8 af2] = 2 l= 2 [4] = 4 fats] = 9 [6] = 4 before sorting + bio] = 3 [a] - 8 a[2] = 2 a[3] = 4 bia] = 4 5] = 9 af6)] = 4 (feer sorting [e] = 3 (2) = 2 2) = 3 Bl. 4 bia] = 4 b{s] = 8 [6] = 9 Test Case -3 (User Output h= 5 Page No: 2 ib: 2200331540075 2022-2026-CSE-0S-8 te Of Technology Raj Kumar Goo! Inst (e] = -36 bia] = -¢0 (2p = 43 aL3] = 54 bra] =o Before sorting = a[@] = -36 ja[1] = -100 y= 43 13] = 54 [4] = 6 ter sorting # [2] = -100 bpay = 43 (2) = 36 a[3] = © bra) = 54 Page No: 3 0: 2200331540075 2022-2026-CSE-0S-8 te Of Technology Raj Kumar Goo! Inst

You might also like