Program to copy the contents of one array into another in the reverse order

The below mentioned program copies the content of one array name ‘source’ into another array named ‘dest’ in the reverse order.
In case you have any queries related to the below mentioned program, please don’t hesitate to comment on this post. Your comments are always welcomed.

#include
#include

void main(){
int source[100], dest[100],i,j,no;
clrscr();
printf("Enter the number of elements: ");
scanf("%d",&no);
 for(i=0;i<no;i++){
  printf("Enter Source Array Element%d :",i+1);
  scanf("%d",&source[i]);
 }
 for(i=0,j=no-1;i<no;i++,j--){
  dest[j]=source[i];
 }
 printf("Destination array:\n");
 for(i=0;i<no;i++){
  printf("%d\t",dest[i]);
 }
 getch();
}

Output:

Enter the number of elements: 10
Enter Source Array Element1 :1                                                  
Enter Source Array Element2 :2                                                  
Enter Source Array Element3 :3                                                  
Enter Source Array Element4 :4                                                  
Enter Source Array Element5 :5                                                  
Enter Source Array Element6 :6                                                  
Enter Source Array Element7 :7                                                  
Enter Source Array Element8 :8                                                  
Enter Source Array Element9 :9                                                  
Enter Source Array Element10 :10                                                
Destination array:                                                               
10     9      8      7      6      5      4      3      2      1       

Also See:
1-Dimensional Array in C Programming Language

You may also like...

7 Responses

  1. Anonymous says:

    void main(){
    int a[5]={1,2,3,4,5},b[5];
    int i,j,count=0;
    for(i=0;i<5;i++){
    printf(“Input array %d\t”,a[i]);
    count++;
    }
    for(j=0;j<5;j++){
    b[j]=a[count];
    count–;
    printf(“Reversed array %d\t”,b[j]);
    }
    }

  2. Anonymous says:

    void main( )
    {
    const int max=5;
    int rev[max]={0},arr[max]={1,2,3,4,5};
    int i;
    for(i=0;i rev[max-1-i]=arr[i];
    for(i=0;igetchar();
    }

  3. Anonymous says:

    nice

  4. Anonymous says:

    love it awsum:)

  5. Wins D Race says:

    for(i=0,j=no-1;i dest[j]=source[i];

    I think this statement plays important role. Will you please explain about “for(i=0,j=no-1;iAnurag

  6. Anonymous says:

    int elements[100];
    int i;
    int numberElements;
    printf(“Donner le nombre des elements : “);
    scanf(“%d”,&numberElements);
    for(i=1;i<=numberElements;i++)
    {
    printf(“Entrer l’element %d : “,i);
    scanf(“%d”,&elements[i]);
    }
    for (i=numberElements; i>=1 ; i–)
    {
    printf(“%d “,elements[i]);
    }
    return 0

  7. Anonymous says:

    How would you do this with a 2-dimmension array?

Leave a Reply

Your email address will not be published. Required fields are marked *

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet