编写一个函数 将7位数的数组中的第2,3,4个数放到另外一个三个数的数组内

#include "stdAfx.h"
#include "ctype.h"
#include "stdlib.h"

int main(void)
{
	void sum_(int a[],int b[]);
	int a[7]={1,6,4,7,1,8,9},b[3],i;

	sum_(a,b);

	for(i=0;i<=2;i++)
		printf("%d ",b[i]);

	putchar('\n');

	system("pause");
    return 0;
}

void sum_(int a[],int b[])
{
	int i,k=0;

	for(i=2;i<=4;i++)
		b[k++]=a[i];
}

指针方法

#include "stdAfx.h"
#include "ctype.h"
#include "stdlib.h"

int main(void)
{
	void sum_(int a[],int b[]);
	int a[7]={1,6,4,7,1,8,9},b[3],i;

	sum_(a,b);

	for(i=0;i<=2;i++)
		printf("%d ",b[i]);

	putchar('\n');

	system("pause");
    return 0;
}

void sum_(int a[],int b[])
{
	int i,* k=b;

	for(i=2;i<=4;i++)
		*k++=a[i];
}


你可能感兴趣的:(编写一个函数 将7位数的数组中的第2,3,4个数放到另外一个三个数的数组内)