1.冒泡排序
#include
int main()
{
int i, j,t;
int a[10];
printf("the array:\n");
for(i=0;i<10;i++)
scanf_s("%d", &a[i]);
for(i=0;i<9;i++)
for(j=0;j<9;j++)
if (a[j] > a[j + 1])
{
t = a[j];
a[j] = a[j+ 1];
a[j+ 1] = t;
}
printf("the new array:\n");
for (i = 0; i < 10; i++)
printf("%d", a[i]);
getchar();
getchar();
return 0;
}
2.递归排序
#include
int main()
{
int i, j,k,t;
int a[10];
printf("the array:\n");
for(i=0;i<10;i++)
scanf_s("%d", &a[i]);
for (i = 0; i < 9; i++)
{
k = i;
for (j = i + 1; j < 10; j++)
if (a[k] > a[j])
k = j;
if (k != i)
{
t = a[i];
a[i] = a[k];
a[k] = t;
}
}
printf("the new line:\n");
for (i = 0; i < 10; i++)
printf("%d", a[i]);
getchar();
getchar();
return 0;
}
3.指针函数的行列互换
#include
int main()
{
void rev(int (*p)[3],int (*p1)[3]);
int a[3][3] = { { 1,2,3 },{4,5,6},{7,8,9} };
int b[3][3];
int i, j;
printf("the array:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
printf("%d", a[i][j]);
printf("\n");
}
rev(a,b);
printf("the new array:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
printf("%d", b[i][j]);
printf("\n");
}
getchar();
getchar();
return 0;
}
void rev(int (*p)[3],int (*p1)[3])
{
int i, j;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
*(*(p1 + j)+i) =*(*(p + i) + j);
}
4.行列互换
#include
int main()
{
void rev(int array[3][3],int b[3][3]);
int a[3][3],b[3][3];
int i, j;
printf("the array:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
scanf_s("%d", &a[i][j]);
printf("\n");
}
printf("the new array:\n");
rev(a,b);
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
printf("%d ", b[i][j]);
printf("\n");
}
getchar();
getchar();
return 0;
}
void rev(int array[3][3],int b[3][3])
{
int i, j;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
b[j][i] = array[i][j];
}
6.结构体
#include
int main()
{
struct Student
{
long int num;
char name[20];
char sex;
char add[20];
}a = { 10101,"lilin",'M',"123 Beijing Road" };
printf("NO.:%d\nname:%s\nsex:%c\naddress:%s\n", a.num, a.name, a.sex, a.add);
getchar();
getchar();
return 0;
}