天天看点

C程序--用函数实现两数组中对应值交换

#include <stdio.h>
#include <stdlib.h>
#define N 5
void Swap(int x[], int y[]);
void GetValue(int array[]);
 void PrintValue(int array[]);
 main()
{
    int A[N],B[N];
    printf("please enter number A: \n");
    GetValue(A);
    printf("please enter number B: \n");
    GetValue(B);
    PrintValue(A);
    PrintValue(B);
    Swap(A,B);
    PrintValue(A);
    PrintValue(B);

}

 void GetValue(int array[])
 {
     int i;
     for(i = 0 ; i < N ; i++)
     {
         scanf("%d",&array[i]);
     }
 }
 void PrintValue(int array[])
 {
     printf(" swap the value is :\n");
     int i;
     for(i = 0 ; i < N ; i++)
     {
         printf("%d  ",array[i]);
     }
     printf("\n");
 }


void Swap(int A[], int B[])
{
    int i,temp;
    for(i = 0; i <N ;i++)
    {
        temp = A[i];
        A[i] = B[i];
        B[i] = temp;
    }

}
           

继续阅读