加循环但是不能排序
#include<stdio.h>
int main()
{
int a[10] = { 0,1,2,3,4,5,6,7,8,9 };
int i = 0, j = 0, n = 0, m, h = 10, r, s, t;
for (r = 5; r > 0; r--)
{
i = 0;
j = 0;
m = 2;
while (j < h)
{
a[i++] = a[j++];
n = i;
if (j == m)
{
j++;
m = m + 3;
}
}
t = j;
h = n;
s = n;
for (i = 0; i < s; i++)
printf("%d ", a[i]);
printf("\n");
n = 0;
}
return 0;
}
可以循环但不是指针
#include<stdio.h>
int main()
{
int a[10] = { 0,1,2,3,4,5,6,7,8,9 };
int i = 0, j = 0, n = 0, m = 2, h = 10, r, s;
for (i = 0; i < 10; i++)
printf("%d ", a[i]);
printf("\n");
for (r = 5; r > 0; r--)
{
i = 0;
while (j < h)
{
a[i++] = a[j++];
n = i;
if (j == m)
{
j++;
m = m + 3;
}
}
h = n;
if (m == j + 2)
{
m = 3;
j = 1;
}
else if (m == j + 1)
{
m = 1;
j = 0;
}
s = n;
for (i = 0; i < s; i++)
printf("%d ", a[i]);
printf("\n");
n = 0;
}
return 0;
}
然后是指针
#include<stdio.h>
void sort(int *p, int u)
{
int i = 0, j = 0, h = u, m = 2, n, r, s;
for (r = 5; r > 0; r--)
{
i = 0;
while (j < h)
{
p[i++] = p[j++];
n = i;
if (j == m)
{
j++;
m = m + 3;
}
}
h = n;
s = n;
if (m == j + 2)
{
m = 3;
j = 1;
}
else if (m == j + 1)
{
m = 1;
j = 0;
}
for (i = 0; i < s; i++)
printf("%d ", p[i]);
printf("\n");
n = 0;
}
}
int main()
{
void sort(int *p, int u);
int a[10] = { 0,1,2,3,4,5,6,7,8,9 };
int i;
for (i = 0; i < 10; i++)
printf("%d ", a[i]);
printf("\n");
sort(a, 10);
return 0;
}
有n个人围成一圈,顺序排号的做题顺序
最新推荐文章于 2023-02-03 20:10:10 发布