Let Us C (Chapter 8 : Arrays) : Program-5

(e) Write a program to copy the contents of one array into another in the reverse order.

let us c chapter 8 arrays problem 5

// Let Us C (Chapter 8 : Arrays) : Program-5
/* Write a program to copy the contents of one array into another in the reverse order */
#include<stdio.h>
int Source[10],Dest[10],i,j,N;
void main()
{
    clrscr();
    printf("Program to copy the contents of array in the reverse order\n");
    printf("How many elements in array?: ");
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        printf("Enter element %d: ",i);
        scanf("%d",&Source[i]);
    }
    printf("\nSource Array is\n");
    for(i=0;i<N;i++)
        printf("%d ",Source[i]);
    j=N;
    for(i=0;i<N;i++)
        Dest[--j] = Source[i];    // copying array in reverse order
    printf("\nDestination array is: \n");
    for(i=0;i<N;i++)
        printf("%d ",Dest[i]);
}
OUTPUT
let us c chapter 8 arrays problem 5 output


Comments

Popular posts from this blog

Chapter 5 : Functions & Pointers (Let us C)

Let Us C (Chapter 8 : Arrays) : Program-9

Chapter 3: The Loop Control Structure (Let Us C)