forked from prashantkalokhe/Hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
even_no_seq.c
58 lines (54 loc) · 1.07 KB
/
even_no_seq.c
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
#include <stdio.h>
#include <conio.h>
#include<time.h>
#include<unistd.h>
int main()
{
time_t begin = time(NULL);
int a[100],b[100],i,n,j,k,temp,count=0;
printf("");
printf("\n Enter size of the array : ");
scanf("%d", &n);
printf("\nEnter elements in array : ");
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
if(a[i]%2==1)
count++;
}
for(i=0; i<n-1; i++)
{
for(j=0; j<n-i-1; j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
k=0;
j=n-count;
for(i=0; i<n; i++)
{
if(a[i]%2==0)
{
if(k<n-count)
b[k++]=a[i];
}
else
{
if(j<n)
b[j++]=a[i];
}
}
printf("\n Array after sorting even and odd elements separately are :\n ");
for(i=0; i<n; i++)
{
a[i]=b[i];
printf("%d ",a[i]);
}
time_t end = time(NULL);
printf("\n\n The Execution time is %d seconds", (end - begin));
}