第一题

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
#include <stdio.h>;
void swap(int *a, int *b);
int main (void)
{
int number[10];
int i, j;//循环变量
while (scanf("%d", &amp;number[0]) != EOF)
{
for (i = 1 ; i &lt; 10 ; i++)
scanf("%d", &amp;number[i]);
for (i = 0 ; i &lt; 9 ; i++)
{
for (j = 0 ; j &lt;= 8 - i ; j++)
{
if (number[j] &gt; number[j+1])
swap(&amp;number[j], &amp;number[j+1]);
}
}
for (i = 0 ; i &lt; 10 ; i++)
{
if (i != 0) printf("-&gt;");
printf("%d", number[i]);
}
putchar('\n');
}
return 0;
}
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
return;
}

第二题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>;
int main (void)
{
long number;
char currentByte;
int count;
while (scanf("%ld", &amp;number) != EOF)
{
for (count = 7 ; count &gt;= 0 ; count--)
{
currentByte = (((0xf &lt;&lt; (count * 4)) &amp; number) &gt;&gt; (count * 4)) &amp; 0xf;
printf("%hd(%c) ", currentByte, currentByte);
}
putchar('\n');
}
return 0;
}

第三题

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
#include <stdio.h>;
void swapArray(int a[], int n);
void swap(int *a, int *b);
int main (void)
{
int number[100];
int totalNumber, individualNumber;
int count, i;//循环变量
scanf("%d", &amp;totalNumber);
for (count = 0 ; count &lt; totalNumber; count++)
{
scanf("%d", &amp;individualNumber);
for (i = 0 ; i &lt; individualNumber ; i++)
scanf("%d", &amp;number[i]);
swapArray(number, individualNumber);
for (i = 0 ; i &lt; individualNumber ; i++)
{
if (i != 0) putchar(' ');
printf("%d", number[i]);
}
putchar('\n');
}
return 0;
}
void swapArray(int a[], int n)
{
int startIndex = 0;
int endIndex = n - 1;
while (startIndex &lt;= endIndex)
{
swap(&amp;a[startIndex], &amp;a[endIndex]);
startIndex++;
endIndex--;
}
return;
}
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
return;
}

第四题

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>;
void swap(int *a, int *b);
void moveArray(int a[], int n, int m);//轮移数组,其中n为总个数,m为轮移次数
int main (void)
{
int number[22];
int individualNumber, middleNumber;
int i;//循环变量
while ((scanf("%d", &amp;individualNumber), individualNumber) != 0)
{
scanf("%d", &amp;middleNumber);
for (i = 0 ; i &lt; individualNumber ; i++)
scanf("%d", &amp;number[i]);
moveArray(number, individualNumber, middleNumber);
for (i = 0 ; i &lt; individualNumber ; i++)
{
if (i != 0) putchar(' ');
printf("%d", number[i]);
}
putchar('\n');
}
return 0;
}
void moveArray(int a[], int n, int m)
{
if (m == 0)
{
return;
}
else
{
int temp, count;
temp = a[0];
for (count = 0 ; count &lt; n - 1 ; count++)
a[count] = a[count+1];
a[n-1] = temp;
moveArray(a, n, --m);
}
}
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
return;
}