void Print(int arr[], int sz)
{
int i = 0;
for (i = 0; i < sz; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
}
void Reverse(int arr[], int sz)
{
int left = 0;
int right = sz - 1;
while (left < right)
{
int tmp = 0;
tmp= arr[left];
arr[left] = arr[right];
arr[right] = tmp;
left++;
right--;
}
}
int main()
{
int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
int sz = sizeof(arr) / sizeof(arr[0]);
Print(arr, sz);
Reverse(arr, sz);
Print(arr, sz);
return 0;
}
//2.数组交换
#include<stdio.h>
int main()
{
int arr1[] = { 1,3,5,7,9 };
int arr2[] = { 2,4,6,8,0 };
int tmp = 0;
int i = 0;
int sz = sizeof(arr1) / sizeof(arr1[0]);
for (i = 0; i < sz; i++)
{
tmp = arr1[i];
arr1[i] = arr2[i];
arr2[i] = tmp;
}
return 0;
}
今日份练习
最新推荐文章于 2024-11-07 23:24:07 发布
本文介绍了两个C语言函数,分别是voidPrint()用于打印数组元素和voidReverse()用于反转数组。还展示了如何在main()中交换两个数组的内容。
摘要由CSDN通过智能技术生成