Co 1st Semester Lab File

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 43

DEPARTMENT OF COMPUTER SCIENCE AND

ENGINEERING
PROGRAMMING FUNDAMENTALS

CO 101
LAB FILE
SUBMITTED TO: SUBMITTEDBY:

S. No. Objective Date Sign


Write a program to count the number of vowels,
14
consonants, whiteSpace and digits in a string.

Write a program to find whether a string is


15
palindrome.

Program to convert a string from lower case to upper


16
case and vice versa.

Program for the addition of two 2 x 2 matrices.


17
Program to multiply two 2 x 2 matrices
18
Program to swap two numbers using pointers
19
Program to generate the employee details using a structure
20
Program to find the area and perimeter of a circle, rectangle,
21 square and triangle using Functions.

Write a program to reverse the indexes of array elements?


17
Write programs for linear searching and binary searching?
18
Write programs for bubble sort and insertion sorting?
19

EXPERIMENT-01

AIM: Write a C program to Print hello world using Printf and hello and world should be in different
lines?

Theory and ALGORITHM:


The given code is a C program that prints "hello" and "World" on separate lines. The algorithm is straightforward:

The program starts with the main function.

It uses the printf function to display "hello" and "World" on separate lines.
Finally, the program returns 0, indicating successful execution.

CODE: This program is written by on

#include<stdio.h>
int main()
{
printf("hello \n World");

return 0;

OUTPUT:
EXPERIMENT-02

AIM: Write a program in C to take two numbers from the user and give output as the sum of two
numbers?

Theory and ALGORITHM:


To take two numbers from the user and output their sum, you can use the following algorithm:

Start the program.

Prompt the user to enter the first number.

Read and store the first number.

Prompt the user to enter the second number.

Read and store the second number.

Compute the sum of the two numbers.

Display the sum as the output.

End the program..

CODE: This program is written by on

OUTPUT:
EXPERIMENT-03

AIM: Write a program to calculate simple interest if principle is p, rate is r and time is t ?

Theory and ALGORITHM:


Theory:

1. The program calculates the simple interest (SI) based on the principle amount (p), rate (r), and time (t).

2. It prompts the user to enter the values of p, r, and t.

3. The input values are read and stored.

4. The simple interest is computed using the formula: SI = (p * r * t) / 100.

5. The program displays the calculated simple interest.

Algorithm:

1. Start the program.

2. Prompt the user to enter the values of p, r, and t.

3. Read and store the input values.

4. Compute the simple interest using the formula: SI = (p * r * t) / 100.

5. Display the calculated simple interest.

6. End the program.

CODE: This program is written by on


}

OUTPUT:
EXPERIMENT-04

AIM: Write a program to find all factors of a number taken from the user?

Theory and ALGORITHM:


The given program takes an input number 'n' from the user and displays all the factors of 'n'. It uses a while loop

to iterate from 1 to 'n' and checks if each number is a factor of 'n'. If it is, it is printed as an output.

Algorithm:

Start the program.

Prompt the user to enter a number 'n'.

Read and store the input value in 'n'.

Initialize a variable 'i' to 1.

Display a message indicating the purpose of the output.

Enter a while loop that continues as long as 'i' is less than or equal to 'n'.

Within the loop, check if 'i' is a factor of 'n' by using the condition 'n % i == 0'.

If the condition is true, print 'i' as a factor of 'n'.

Increment 'i' by 1.

Repeat steps 7-9 until the while loop condition is met.

End the program.

CODE: This program is written by on


}
OUTPUT:
EXPERIMENT-05

AIM: Write a code to check whether the entered number is prime or not?

Theory and ALGORITHM:


Theory: The given program takes an input number 'n' from the user and determines whether it is a prime number

or not. It uses a while loop to iterate from 1 to 'n' and counts the number of factors of 'n'. If 'n' has exactly two

factors (1 and itself), it is considered a prime number.

Algorithm:

1. Start the program.

2. Prompt the user to enter a number 'n'.

3. Read and store the input value in 'n'.

4. Initialize a variable 'i' to 1 and a counter variable 'count' to 0.

5. Enter a while loop that continues as long as 'i' is less than or equal to 'n'.

6. Within the loop, check if 'i' is a factor of 'n' by using the condition 'n % i == 0'.

7. If the condition is true, increment the 'count' variable by 1.

8. Increment 'i' by 1.

9. Repeat steps 6-8 until the while loop condition is met.

10. Check if the 'count' variable is equal to 2.

11. If the condition is true, print "given number is prime".

12. If the condition is false, print "given number is not prime".

13. End the program.

CODE: This program is written by on


}

OUTPUT:
EXPERIMENT-06

AIM: Write a program to find all factors of a number taken from the user?

Theory and ALGORITHM: Theory: The given program generates and prints the Fibonacci
series up to a given number 'n'. It starts with the initial values of 'a' and 'b' as 0 and 1, respectively. It

then uses a while loop to calculate the Fibonacci sequence by adding the previous two numbers and

updating the values of 'a' and 'b'. The loop continues until it reaches 'n + 1' terms, and each number in

the sequence is printed.

Algorithm:

1. Start the program.

2. Prompt the user to enter a number 'n'.

3. Read and store the input value in 'n'.

4. Initialize variables 'a' and 'b' to 0 and 1, respectively.

5. Initialize a loop counter 'i' to 1.

6. Enter a while loop that continues as long as 'i' is less than or equal to 'n + 1'.

7. Within the loop, print the value of 'a'.

8. Calculate the next Fibonacci number by adding 'a' and 'b' and store it in a variable 'sum'.

9. Update 'a' with the value of 'b' and 'b' with the value of 'sum'.

10. Increment 'i' by 1.

11. Repeat steps 7-10 until the while loop condition is met.

12. End the program.

CODE: This program is written by on


}
OUTPUT:
EXPERIMENT-07

AIM: Write a program to find GCD of two numbers?

Theory and ALGORITHM:


Theory: The given program finds the Highest Common Factor (HCF) of two numbers entered by the

user. It uses the Euclidean algorithm, which repeatedly divides the larger number by the remainder

obtained from the division of the two numbers until the remainder becomes zero. The final non-zero

remainder is the HCF of the two numbers.

Algorithm:

1. Start the program.

2. Prompt the user to enter two numbers, the dividend, and the divisor.

3. Read and store the input values in 'dividend' and 'divisor'.

4. Enter a while loop that continues indefinitely (while loop with condition 1, which is always true).

5. Within the loop, calculate the remainder of the division of 'dividend' by 'divisor' and store it in the

variable 'rem'.

6. Check if the remainder 'rem' is equal to 0.

7. If the condition is true, break out of the loop.

8. Update the value of 'dividend' to 'divisor' and 'divisor' to 'rem'.

9. Repeat steps 5-8 until the while loop condition is met.

10. Print the value of 'divisor', which represents the HCF of the two numbers.

11. End the program.

CODE: This program is written by on


}

OUTPUT:
EXPERIMENT-08

AIM: Write a program to find which number is greater among 3 numbers?

Theory and ALGORITHM:


Theory: The given program determines the greatest among three numbers entered by the user. It compares the

three numbers using if statements and assigns the greatest value to a variable called 'greatest'. Finally, it displays

the value of 'greatest' as the output.

Algorithm:

1. Start the program.

2. Prompt the user to enter three numbers.

3. Read and store the input values in variables: 'num1', 'num2', and 'num3'.

4. Initialize a variable called 'greatest' with the value of 'num1'.

5. Compare 'num2' with 'greatest' using an if statement.

6. If 'num2' is greater than 'greatest', update the value of 'greatest' to 'num2'.

7. Compare 'num3' with 'greatest' using an if statement.

8. If 'num3' is greater than 'greatest', update the value of 'greatest' to 'num3'.

9. Display the value of 'greatest' as the output.

10. End the program.

CODE: This program is written by on

#include <stdio.h>

int main() {
int num1, num2, num3;

printf("Enter three numbers: ");


scanf("%d %d %d", &num1, &num2, &num3);

int greatest = num1;

if (num2 > greatest) {


greatest = num2;
}
if (num3 > greatest) {
greatest = num3;
}

printf("The greatest number is: %d\n", greatest);

return 0;
}
OUTPUT:
EXPERIMENT-09

AIM: Write a program to find whether the number is even or odd?

Theory and ALGORITHM:


Theory: The given program determines whether a number is even or odd. It takes a number from the

user and checks if the number is divisible by 2. If the remainder of the division is zero, it is an even

number. Otherwise, it is an odd number.

Algorithm:

1. Start the program.

2. Prompt the user to enter a number.

3. Read and store the input value in the variable 'num'.

4. Check if the number 'num' is divisible by 2 using the condition 'num % 2 == 0'.

5. If the condition is true, display "The number is even."

6. If the condition is false, display "The number is odd."

7. End the program.

CODE: This program is written by on


}
#include <stdio.h>

int main() {
int num;

printf("Enter a number: ");


scanf("%d", &num);

if (num % 2 == 0) {
printf("The number is even.\n");
} else {
printf("The number is odd.\n");
}

return 0;
}
OUTPUT:
EXPERIMENT-10

AIM: Write a program to print counting from 1 to n where n is natural number ?

Theory and ALGORITHM:

CODE: This program is written by on }


#include <stdio.h>

int main() {
int n;

printf("Enter the value of n: ");


scanf("%d", &n);

for (int i = 1; i <= n; i++) {


printf("%d ", i);
}

return 0;
}
OUTPUT:
EXPERIMENT-11

AIM: Write a program to find sum of n natural numbers?

Theory and ALGORITHM:


Theory: The given program calculates the sum of the first 'n' natural numbers. It prompts the user to

enter a value for 'n', and then it uses a loop to iterate from 1 to 'n' and calculate the sum of the numbers.

Algorithm:

1. Start the program.

2. Prompt the user to enter the value of 'n'.

3. Read and store the input value in the variable 'n'.

4. Initialize a variable called 'sum' to 0.

5. Use a 'for' loop to iterate from 1 to 'n' (inclusive).

6. Within the loop, add the value of the loop variable to 'sum'.

7. Repeat steps 5-6 until the loop variable reaches the value of 'n'.

8. Display the value of 'sum' as the sum of the first 'n' natural numbers.

9. End the program.

CODE: This program is written by on


}
#include <stdio.h>

int main() {
int n, sum = 0;

printf("Enter the value of n: ");


scanf("%d", &n);

for (int i = 1; i <= n; i++) {


sum += i;
}

printf("The sum of first %d natural numbers is %d\n", n, sum);

return 0;
}
OUTPUT:
EXPERIMENT-12

AIM: Write a program to find factorial of a number?

Theory and ALGORITHM:


Theory: The given program calculates the factorial of a given number. It prompts the user to enter a

number, and then it uses a loop to iterate from 1 to the given number and calculate the factorial.

Algorithm:

1. Start the program.

2. Prompt the user to enter a number.

3. Read and store the input value in the variable 'n'.

4. Initialize a variable called 'factorial' to 1.

5. Use a 'for' loop to iterate from 1 to 'n' (inclusive).

6. Within the loop, multiply the value of the loop variable with the 'factorial'.

7. Repeat steps 5-6 until the loop variable reaches the value of 'n'.

8. Display the value of 'factorial' as the factorial of the given number 'n'.

9. End the program.

CODE: This program is written by on


}
#include <stdio.h>

int main() {
int n;
unsigned long long factorial = 1;

printf("Enter a number: ");


scanf("%d", &n);

for (int i = 1; i <= n; i++) {


factorial *= i;
}

printf("The factorial of %d is %llu\n", n, factorial);

return 0;
}
OUTPUT:
EXPERIMENT-13(A)

AIM: Write a program to reverse a number(Jugaadu method)?

Theory and ALGORITHM:


Theory: The given program takes an integer as input and prints its digits in reverse order. It uses a while

loop to extract each digit from the number and print it.

Algorithm:

1. Start the program.

2. Prompt the user to enter a number.

3. Read and store the input value in the variable 'n'.

4. Enter a while loop with the condition 'n != 0'.

5. Within the loop, calculate the remainder of 'n' when divided by 10 using 'rem = n % 10'.

6. Print the value of 'rem', which represents the last digit of the number.

7. Update the value of 'n' by dividing it by 10 using 'n = n / 10'.

8. Repeat steps 5-7 until 'n' becomes 0.

9. End the program.

CODE: This program is written by on

#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
while (n != 0)
{
int rem = n % 10;
printf("%d", rem);
n=n/10;

return 0;
}
OUTPUT:
EXPERIMENT-13(B)

AIM: Write a program to reverse a number(permanent method)?

Theory and ALGORITHM:


Theory: The given program takes an integer as input and reverses its digits. It uses a while loop to

extract each digit from the number, build the reversed number, and finally, prints the reversed number.

Algorithm:

1. Start the program.

2. Prompt the user to enter a number.

3. Read and store the input value in the variable 'n'.

4. Initialize a variable 'ans' to 0 to store the reversed number.

5. Enter a while loop with the condition 'n != 0'.

6. Within the loop, calculate the remainder of 'n' when divided by 10 using 'rem = n % 10'.

7. Update the value of 'ans' by multiplying it by 10 and adding 'rem'.

8. Update the value of 'n' by dividing it by 10.

9. Repeat steps 6-8 until 'n' becomes 0.

10. Print the value of 'ans', which represents the reversed number.

11. End the program.

CODE: This program is written by on


}
#include <stdio.h>
int main()
{
int n,ans=0;
scanf("%d", &n);
while (n != 0)
{
int rem = n % 10;
ans=ans*10+rem;

n=n/10;

}
printf("%d",ans);

return 0;
}

OUTPUT:
EXPERIMENT-14

AIM: Write a program to print all array elements?

Theory and ALGORITHM:


The given program allows the user to input the number of elements in an array and the values for each

element. It then displays the entered array elements.

Algorithm:

1. Start the program.

2. Prompt the user to enter the number of elements in the array.

3. Read and store the input value in the variable 'n'.

4. Declare an integer array 'arr' of size 'n' to store the elements.

5. Prompt the user to enter the array elements.

6. Use a 'for' loop to iterate from 0 to 'n-1' and read each element into 'arr[i]'.

7. Display a message to indicate the array elements.

8. Use another 'for' loop to iterate from 0 to 'n-1' and print each element of the array.

9. Repeat step 8 until all array elements are printed.

10. End the program.

CODE: This program is written by on


}
#include <stdio.h>
int main(int argc, char const *argv[])
{

int n, i;
printf("enter the number of elements in an array=");
scanf("%d", &n);
int arr[n];
printf("enter your array elements=\n");
for (int i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
printf("your array elements are \n");
for (int i = 0; i<n; i++)
{
printf("%d\n", arr[i]);
}

return 0;
}

OUTPUT:
EXPERIMENT-15

AIM: Write a program to print all array elements in reverse order?

Theory and ALGORITHM:

Theory: The given program allows the user to input the number of elements in an array and the values for each
element. It then prints the array elements in reverse order.
Algorithm:
1. Start the program.
2. Prompt the user to enter the number of elements in the array.
3. Read and store the input value in the variable 'n'.
4. Declare an integer array 'arr' of size 'n' to store the elements.
5. Prompt the user to enter the array elements.
6. Use a 'for' loop to iterate from 0 to 'n-1' and read each element into 'arr[i]'.
7. Display a message to indicate that the program will print the array elements in reverse order.
8. Use another 'for' loop to iterate from 'n-1' to 0 in reverse order.
9. Within the loop, print each element of the array.
10. Repeat step 9 until all array elements are printed in reverse order.
11.End the program.

CODE: This program is written by on

#include <stdio.h>

int main() {
int n;
printf("Enter the number of elements in the array: ");
scanf("%d", &n);

int arr[n];
printf("Enter the array elements:\n");
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

printf("Array elements in reverse order:\n");


for (int i = n - 1; i >= 0; i--) {
printf("%d\n", arr[i]);
}

return 0;
}
}

OUTPUT:
EXPERIMENT-16

AIM: Write a program to find the maximum out of all array elements?

Theory and ALGORITHM:


Theory: The given program allows the user to input the number of elements in an array and the values

for each element. It then finds the maximum value among all the elements in the array and displays it.

Algorithm:

1. Start the program.

2. Prompt the user to enter the number of elements in the array.

3. Read and store the input value in the variable 'n'.

4. Declare an integer array 'arr' of size 'n' to store the elements.

5. Prompt the user to enter the array elements.

6. Use a 'for' loop to iterate from 0 to 'n-1' and read each element into 'arr[i]'.

7. Initialize a variable 'max' with the first element of the array ('arr[0]').

8. Use another 'for' loop to iterate from 1 to 'n-1'.

9. Within the loop, compare each element of the array with the current maximum value 'max'.

10. If an element is greater than 'max', update 'max' to the new maximum value.

11. Repeat step 9 until all elements are checked.

12. Display the maximum element found in the array.

13. End the program.

CODE: This program is written by on


#include <stdio.h>

int main() {
int n;
printf("Enter the number of elements in the array: ");
scanf("%d", &n);

int arr[n];
printf("Enter the array elements:\n");
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

int max = arr[0];


for (int i = 1; i < n; i++) {
if (arr[i] > max) {
max = arr[i];
}
}

printf("The maximum element in the array is: %d\n", max);

return 0;
}
OUTPUT:
EXPERIMENT-17

AIM: Write a program to reverse the indexes of array elements?

Theory and ALGORITHM:


The given program allows the user to input the number of elements in an array and the values for each

element. It then reverses the indexes of the array elements and displays them.

Algorithm:

1. Start the program.

2. Prompt the user to enter the number of elements in the array.

3. Read and store the input value in the variable 'n'.

4. Declare an integer array 'arr' of size 'n' to store the elements.

5. Prompt the user to enter the array elements.

6. Use a 'for' loop to iterate from 0 to 'n-1' and read each element into 'arr[i]'.

7. Declare another integer array 'reversedArr' of size 'n' to store the reversed elements.

8. Use a 'for' loop to iterate from 0 to 'n-1'.

9. Assign each element of 'arr' to 'reversedArr' at the reversed index position ('reversedArr[n - 1 - i]

= arr[i]').

10. Display the array elements after reversing the indexes.

11. Use a 'for' loop to iterate from 0 to 'n-1'.

12. Display each element of 'reversedArr' on a new line.

13. End the program.

CODE: This program is written by on


}
#include <stdio.h>

int main() {
int n;
printf("Enter the number of elements in the array: ");
scanf("%d", &n);

int arr[n];
printf("Enter the array elements:\n");
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

int reversedArr[n];
for (int i = 0; i < n; i++) {
reversedArr[n - 1 - i] = arr[i];
}

printf("Array elements after reversing the indexes:\n");


for (int i = 0; i < n; i++) {
printf("%d\n", reversedArr[i]);
}

return 0;
}
OUTPUT:
EXPERIMENT-18

AIM: Write programs for linear searching and binary searching?

Theory and ALGORITHM:


Theory:

Linear Search: Linear search is a simple search algorithm that sequentially checks each element in a

list/array until a match is found or the end of the list is reached. It is suitable for unordered lists.

Algorithm:

1. Start at the beginning of the list.

2. Iterate through each element in the list.

3. Check if the current element matches the search key.

4. If a match is found, return the index of the element.

5. If the end of the list is reached without a match, return -1 to indicate that the key was not found.

Binary Search: Binary search is an efficient search algorithm that works on sorted lists/arrays. It

repeatedly divides the search space in half by comparing the middle element with the search key until

the key is found or the search space is empty.

Algorithm:

1. Start with the entire sorted list/array.

2. Set the lower bound (left) to the first index and the upper bound (right) to the last index.

3. Repeat the following steps until the search space is empty: a. Calculate the middle index as (left

+ right) / 2. b. Compare the middle element with the search key: - If the middle element is equal

to the key, return the middle index. - If the middle element is greater than the key, set the new

upper bound to middle - 1. - If the middle element is smaller than the key, set the new lower

bound to middle + 1.

4. If the search space is empty and the key is not found, return -1 to indicate that the key was not

found.
CODE: 1.linear search This program is written by on
}
#include <stdio.h>

int linearSearch(int arr[], int n, int key) {


for (int i = 0; i < n; i++) {
if (arr[i] == key) {
return i; // Return the index if key is found
}
}
return -1; // Return -1 if key is not found
}

int main() {
int n, key;
printf("Enter the number of elements in the array: ");
scanf("%d", &n);

int arr[n];
printf("Enter the array elements:\n");
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

printf("Enter the key to search: ");


scanf("%d", &key);

int index = linearSearch(arr, n, key);


if (index != -1) {
printf("Key %d found at index %d.\n", key, index);
} else {
printf("Key %d not found in the array.\n", key);
}

return 0;
}
OUTPUT:
CODE: 2.Binary search This program is written by on

#include <stdio.h>

int binarySearch(int arr[], int low, int high, int key) {

while (low <= high) {

int mid = low + (high - low) / 2;

if (arr[mid] == key) {

return mid; // Return the index if key is found

else if (arr[mid] < key) {

low = mid + 1; // Search in the right half

else {

high = mid - 1; // Search in the left half

return -1; // Return -1 if key is not found

int main() {

int n, key;

printf("Enter the number of elements in the array: ");

scanf("%d", &n);

int arr[n];

printf("Enter the sorted array elements:\n");

for (int i = 0; i < n; i++) {

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

}
printf("Enter the key to search: ");

scanf("%d", &key);

int index = binarySearch(arr, 0, n - 1, key);

if (index != -1) {

printf("Key %d found at index %d.\n", key, index);

} else {

printf("Key %d not found in the array.\n", key);

return 0;

OUTPUT:
EXPERIMENT-19

AIM: Write programs for bubble sort and insertion sorting?

Theory and ALGORITHM:


Theory:

Bubble Sort: Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares

adjacent elements, and swaps them if they are in the wrong order. It continues to iterate through the list

until no more swaps are needed, indicating that the list is sorted.

Algorithm:

1. Start at the beginning of the list.

2. Compare each pair of adjacent elements.

3. If the elements are in the wrong order, swap them.

4. Continue iterating through the list, repeating steps 2 and 3, until no more swaps are needed.

5. The largest element will "bubble" to the end of the list after each iteration.

6. Repeat the above steps for the remaining unsorted portion of the list until the entire list is sorted.

Insertion Sort: Insertion sort is a simple sorting algorithm that builds the final sorted array one item at a

time. It iterates through the list, considering one element at a time, and inserts it into its correct position

in the sorted portion of the array.

Algorithm:

1. Start with the second element (index 1) and assume it is the first element of the sorted portion.

2. Iterate through the remaining elements in the list.

3. Compare the current element with the elements in the sorted portion from right to left.

4. Shift the elements in the sorted portion that are greater than the current element to the right.

5. Insert the current element into its correct position in the sorted portion.

6. Repeat steps 2 to 5 until all elements are considered and inserted into the sorted portion.

CODE: 1.Bubble sort This program is written by on


#include <stdio.h>

void bubbleSort(int arr[], int n) {


int i, j;
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
// Swap arr[j] and arr[j+1]
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}

int main() {
int n, i;
printf("Enter the number of elements in the array: ");
scanf("%d", &n);

int arr[n];
printf("Enter the array elements:\n");
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

// Sort the array using bubble sort


bubbleSort(arr, n);

printf("Array elements after sorting:\n");


for (i = 0; i < n; i++) {
printf("%d ", arr[i]);
}

return 0;
}
}

OUTPUT:
CODE: 2.Insertion sort This program is written by on

#include <stdio.h>

void insertionSort(int arr[], int n) {


int i, j, key;
for (i = 1; i < n; i++) {
key = arr[i];
j = i - 1;

// Move elements greater than key to one position ahead


while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
int main() {
int n, i;
printf("Enter the number of elements in the array: ");
scanf("%d", &n);

int arr[n];
printf("Enter the array elements:\n");
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

// Sort the array using insertion sort


insertionSort(arr, n);

printf("Array elements after sorting:\n");


for (i = 0; i < n; i++) {
printf("%d ", arr[i]);
}

return 0;
}
OUTPUT:

You might also like