-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest133.c
More file actions
56 lines (55 loc) · 733 Bytes
/
test133.c
File metadata and controls
56 lines (55 loc) · 733 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
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <math.h>
int pow_number(int x, int y)
{
int a = x;
if (y == 0)
return 1;
while(y != 1)
{
x *= a;
y--;
}
return x;
}
int judgedigit(int x)
{
int i = 0,a = x,k;
while(x != 0)
{
x /= 10;
i++;
}
k = a / (pow_number(10,i-1));
return k;
}
void startingdigit(int A[],int length)
{
int i,j,tmp,a1,a2;
for(i = 0; i < length-1; i++)
{
for(j = 0; j < length-i-1; j++)
{
a1 = judgedigit(A[j]);
a2 = judgedigit(A[j+1]);
if(a1 > a2)
{
tmp = A[j];
A[j] = A[j+1];
A[j+1] = tmp;
}
}
}
return;
}
int main()
{
int A[5],i;
for(i = 0; i < 5; i++)
scanf("%d",&A[i]);
startingdigit(A,5);
for(i = 0; i < 5; i++)
printf("%d ",A[i]);
printf("\n");
return 0;
}