【C语言】转换一维数组

前端之家收集整理的这篇文章主要介绍了【C语言】转换一维数组前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <stdio.h>
#define MAX_SIZE 20   /* 最大数组个数 */

void TransposeArray(int *arr,int size);

int main()
{
	int size = 0;
	int orien_arr[MAX_SIZE] = {0,};

	printf("Input N: \n");
	scanf("%d",&size);
	printf("The Orign Array is :\n");

	for (int i = 0; i < size; i++)
	{
		scanf("%d",orien_arr+i);
	}

	TransposeArray(orien_arr,size); 
	printf("The Transposed Array is :\n");

	for (int i = 0; i < size; i++)
	{
		printf("%d\t",*(orien_arr+i));
	}

	printf("\n");
	return 0;
}

/*转换函数*/
void TransposeArray(int *arr,int size)
{
	for (int i = 0; i <= (size-1)/2; i++)
	{
		int tmp = *(arr+i);
		*(arr+i) = *(arr+size-i-1);
		*(arr+size-i-1) = tmp;
	}
}
原文链接:https://www.f2er.com/javaschema/285753.html

猜你在找的设计模式相关文章