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) : 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
Comments
Post a Comment