-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecond_maximum.c
More file actions
47 lines (47 loc) · 1012 Bytes
/
Copy pathsecond_maximum.c
File metadata and controls
47 lines (47 loc) · 1012 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
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
int* remove_duplicate(int array[],int length)
{
int i,j,k;
for(i=0;i<length;i++)
{
for(j=i+1;j<length;j++)
{
if(array[i]==array[j])
{
for(k=j;k<length;k++)
{
array[k]=array[k+1];
}
length--;
k--;
}
}
}
return array;
}
void main()
{
int test[]={1,8,8,4,5};
int len,i,j,temp;
len=*(&test+1)-test;
printf("the size is: %d\n",len);
for(i=0;i<len;i++)
{
for(j=i+1;j<len;j++)
{
if(test[i]>test[j])
{
temp=test[i];
test[i]=test[j];
test[j]=temp;
}
}
}
printf("The elements of array are:");
int test1[]=remove_duplicate(test,len);
for(i=0;i<len;i++)
{
printf("%d\t",test1[i]);
}
printf("\nThe second maximum element is: %d",test[len-2]);
}