#include <stdio.h>
int quick(int arr[], int left, int right)
{
int i = left;
int len = sizeof(arr) / sizeof(arr[0]);
int j = right;
int tmp = arr[0];
if (left >= right)
return;
else
{
while (i < j)
{
if (tmp>arr[j])
{
arr[i] = arr[j];
while (i<j)
{
if (tmp > arr[i])
{
i++;
}
else
{
arr[j] = arr[i];
break;
}
}
}
else
{
j--;
}
}
arr[i] = tmp;
quick(arr, left, i - 1);
quick(arr, j + 1, right);
}
}
int main()
{
int arr[] = { 12, 2, 4, 14, 7, 6, 11 };
int len = sizeof(arr) / sizeof(arr[0]);
quick(arr, 0, len - 1);
int i = 0;
for (i = 0; i < len; ++i)
{
printf("%d ", arr[i]);
}
printf("\n");
system("pause");
}
#include <stdio.h>
int main()
{
int *p1;
int i = 0;
int j = 0;
int m = 0;
int n = 0;//m代表行数 n代表列数
printf("please input m,n:\n");
scanf("%d%d", &m, &n);
p1 = (int *)malloc(m*n*sizeof(*p1));
if (p1 == NULL)
printf("out of memory\n");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
p1[i*m + j] = 1;
printf("%2d", p1[i*m + j]);
}
printf("\n");
}
free(p1);
system("pause");
return 0;
}
原文地址:http://10541695.blog.51cto.com/10531695/1696012