-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubblefunction.c
More file actions
58 lines (55 loc) · 1.58 KB
/
Copy pathbubblefunction.c
File metadata and controls
58 lines (55 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*-------------------------------------------------------------------------------------------------------------------------------
BubbleFun.c
Program to sort n numbers in ascending order using bubble sort (Use user defined functions).
DIVYA RAJ K
25-09-2018
---------------------------------------------------------------------------------------------------------------------------------*/
#include<stdio.h>
#include<math.h>
//----------------------------------prototype---------------------------------------------
void fnInputArray(int N,int A[30]);
void fnBubbleSort(int N,int A[30]);
void fnPrintArray(int N,int A[30]);
main()
{
int X[30],N,i,j,Temp;
system("clear");
printf("Program to sort n numbers in ascending order using bubble sort\n\n");
printf("Enter the number of elements: ");
scanf("%d",&N);
fnInputArray(N,X);
fnBubbleSort(N,X);
printf("\nThe entered numbers after sorting are:\n");
fnPrintArray(N,X);
}
//----------------------------------fnInputArray---------------------------------------------
void fnInputArray(int N,int A[30])
{
int i;
printf("Enter %d numbers:\n",N);
for(i=1;i<=N;i++){
scanf("%d",&A[i]);
}
}
//----------------------------------fnBubbleSort---------------------------------------------
void fnBubbleSort(int N,int A[30])
{
int i,j,Temp;
for(i=1;i<=(N-1);i++){
for(j=1;j<=(N-i);j++){
if(A[j]>A[j+1]){
Temp=A[j];
A[j]=A[j+1];
A[j+1]=Temp;
}
}
}
}
//----------------------------------fnPrintArray---------------------------------------------
void fnPrintArray(int N,int A[30])
{
int i;
for(i=1;i<=N;i++){
printf("%d\t",A[i]);
}
}