Saturday, 7 July 2012

To copy the contents of an array A to contents of Array B without using loops and any standard string copy functions.


#include<stdio.h>
int Copy_Array(int A[],int B[], int n,int i)
{
    if(i==n)
        return 0;
    B[i]=A[i];
    Copy_Array(A,B,n,i+1);
return 0;
}

int main()
{
    int A[10],B[10],i,n;
    printf("Enter size : ");
    scanf("%d",&n);
    printf("Enter Array : ");
    for(i=0;i<n;i++)
        scanf("%d",&A[i]);
    printf("\nArray A : ");
    for(i=0;i<n;i++)
        printf("%d ",A[i]);
    Copy_Array(A,B,n,0);
    printf("\nArray B : ");
    for(i=0;i<n;i++)
        printf("%d ",B[i]);
return 0;
}


Let me know your thoughts.

No comments:

Post a Comment