0% found this document useful (0 votes)
11 views5 pages

EXP 5 Final Report

The document outlines a laboratory experiment for a Computer Programming course focused on implementing the bubble sort algorithm in C programming. It details the objective of learning to use arrays and loops, the methodology for sorting numbers, and includes the algorithm and code used. The conclusion highlights the understanding gained from the experiment regarding sorting techniques and programming skills.

Uploaded by

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

EXP 5 Final Report

The document outlines a laboratory experiment for a Computer Programming course focused on implementing the bubble sort algorithm in C programming. It details the objective of learning to use arrays and loops, the methodology for sorting numbers, and includes the algorithm and code used. The conclusion highlights the understanding gained from the experiment regarding sorting techniques and programming skills.

Uploaded by

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

Department of Electrical and Electronic Engineering

Course Title: Computer Programming Laboratory


Course Code: EEE134.11

Submitted To
Name: Md. Shahriar Khan Hemel
Designation: Lecturer
Dept. of Electrical and Electronic Engineering

Submitted By
Name: Syed Tahsinul Islam
ID: 2024200520067
Batch: 18/B
Program: B.Sc. in EEE

Submitted on:
Submitted on ___/___/___
Experiment No: 5
Experiment Name:
Perform sorting operation using bubble sort.

Objective:
 To understand how to use arrays in C programming.
 To learn how to swap numbers using loops.

Introduction:
Sorting means arranging numbers in a specific order, like from smallest to biggest or biggest to
smallest. It is useful in many areas, like showing student marks, phone numbers, or prices. In
this experiment, we use bubble sort, which is a simple way to sort numbers by checking two
numbers at a time and swapping them if needed.

This program helps to solve the problem of organizing numbers. A user can enter any five
numbers, and the program will sort them. This makes it easier to work with the numbers in the
right order.

Methodology:
We wrote a C program to sort numbers using the bubble sort method. Here’s what the program
does:
 It first asks the user to enter 5 numbers.
 Then it checks each pair of numbers.
 If a number is bigger than the next one, they are swapped.
 This continues until all numbers are in the right order.
This is done using arrays, loops, and a temporary variable for swapping values.
Algorithm:
1. Start
2. Declare array a[n], variables i, j, temp
3. Set value of n (e.g., define n = 5)
4. Assign i = 0
5. If i < n then move to next step, else move to step 7
6. Take input a[i] and move to step 5
7. Assign i = 0
8. If i < n - 1 then move to next step, else move to step 15
9. Assign j = 0
10. If j < n - i - 1 then move to next step, else move to step 14
11. If a[j] > a[j + 1] then move to next step, else move to step 13
12. Assign temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp
13. Move to step 10
14. Move to step 8
15. Print numbers in descending order
16. Assign i = 0
17. If i < n then move to next step, else move to step 19
18. Print values of a[i]
19. End

Procedure:
1. First, I opened CodeBlocks (or you can use any C compiler you prefer).
2. Then, I typed the bubble sort code exactly as shown in the lab instructions.
3. After writing the code, I clicked on “Build and Run” to compile and execute it.
4. When the program asked for input, I entered 5 different numbers.
5. The program processed the numbers and displayed them in descending order on the
screen
Code:
#include<stdio.h>
#define n 5
int main()
{
int a[n];
int i,j,temp;
printf ("Enter %d numbers:",n);
for (i=0;i<n;i++)
scanf ("%d",&a[i]);
for (i=0;i<n-1;i++)
for (j=0;j<n-1-i;j++)
if (a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
printf ("\nNnumber is descending order: ");
for (i=0;i<n;i++)
printf ("%d ",a[i]);
return 0;
}

Result:

Conclusion:
From this experiment, I learned how bubble sort works by comparing and swapping numbers
using loops. I also learned how to use arrays in a C program. This experiment helped me
understand how sorting is done in a simple and easy way, which will help me in other
programming problems in the future.

You might also like