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
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]);
}
}
void main( ) rev[max-1-i]=arr[i]; getchar();
{
const int max=5;
int rev[max]={0},arr[max]={1,2,3,4,5};
int i;
for(i=0;i
for(i=0;i
}
nice
love it awsum:)
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;i Anurag
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
How would you do this with a 2-dimmension array?