-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest115.c
More file actions
109 lines (108 loc) · 1.49 KB
/
test115.c
File metadata and controls
109 lines (108 loc) · 1.49 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <stdio.h>
#include <stdlib.h>
int randomInt(int n)
{
return rand()%n;
}
void sortUparray(int A[],int n)
{
int i,j,tmp;
for(i = 0; i < n-1; i++)
{
for(j = 0; j < n-1-i; j++)
{
if (A[j] > A[j+1])
{
tmp = A[j];
A[j] = A[j+1];
A[j+1] = tmp;
}
}
}
return;
}
void printarray(int A[],int n)
{
int i;
for(i = 0; i < n; i++)
printf("a[%d] = %d ",i,A[i]);
printf("\n");
return;
}
void sortarray_even_uneven(int a[],int n)
{
int i,b[n],k = 0;
for(i = 0; i < n; i++)
{
if (a[i] % 2 == 0)
{
b[k] = a[i];
k++;
}
}
for(i = 0; i < n; i++)
{
if (a[i] % 2 != 0)
{
b[k] = a[i];
k++;
}
}
for(i = 0; i < n; i++)
a[i] = b[i];
return;
}
int element_array(int a[], int n)
{
int b[n],c[n],i,j,k = 0,k_count,count_element,type = 0,newtype = 1,max_times = 1,max_index = 0;
for(i = 0; i < n; i++)
{
count_element = 1;
if(i != 0)
{
for (k_count = 0; k_count < k; k_count++)
{
if (a[i] == b[k_count])
{
newtype = 0;
break;
}
}
}
if (newtype != 0)
type = 0 ;
for(j = i + 1; j < n; j++)
{
if(a[i] == a[j])
count_element++;
}
c[k] = count_element++;
if(type == 0)
{
b[k] = a[i];
k++;
type = 1;
}
newtype = 1;
}
for(i = 0; i < k; i++)
printf("%d -- %d ",b[i],c[i]);
printf("\n");
return 0;
}
int main()
{
int n,i = 0,j,a[10];
scanf("%d",&n);
while(n != 0)
{
a[i] = n%10;
n /= 10;
i++ ;
}
sortUparray(a,i);
for(j = 0; j < i; j++)
printf("%d",a[j]);
printf("\n");
return 0;
}