forked from eperrier2001/Cpp.Playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting.c
More file actions
38 lines (35 loc) · 635 Bytes
/
sorting.c
File metadata and controls
38 lines (35 loc) · 635 Bytes
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
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main() {
int a;
int c=0;
scanf("%d",&a);
int h[a];
for(int i=0;i<a;i++)
{
scanf("%d",&h[i]);
}
for(int j=0;j<a;j++)
{
for(int l=0;l<a-1;l++)
{
if(h[l]>=h[l+1])
{
int k;
k=h[l];
h[l]=h[l+1];
h[l+1]=k;
c++;
}
}
}
printf("Array is sorted in %d swaps.\n",c);
printf("First Element: %d\n",h[0]);
printf("Last Element: %d",h[a-1]);
return 0;
}