Question-Write a program to copy the contents of one array into another
in the reverse order.
Solution-A good Question. let's look up the solution.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int array1[5],i;
printf("Enter the elements of the first array\n");
for(i=0;i<=4;i++)
scanf("%d",&array1[i]);
copyarr(array1);
getch();
}
copyarr(int *array1)
{
int *array2[5];
int i,j,k;
for(i=0;i<5;)
{
for(j=4;j>=0;j--)
{
array2[j]=array1[i]; /* Storing it into a different array */
i++;
}
}
printf("Copied elements stored in 2nd array are\n");
for(k=0;k<=4;k++)
printf("%d ",*(array2+k));
}
in the reverse order.
Solution-A good Question. let's look up the solution.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int array1[5],i;
printf("Enter the elements of the first array\n");
for(i=0;i<=4;i++)
scanf("%d",&array1[i]);
copyarr(array1);
getch();
}
copyarr(int *array1)
{
int *array2[5];
int i,j,k;
for(i=0;i<5;)
{
for(j=4;j>=0;j--)
{
array2[j]=array1[i]; /* Storing it into a different array */
i++;
}
}
printf("Copied elements stored in 2nd array are\n");
for(k=0;k<=4;k++)
printf("%d ",*(array2+k));
}
Give a Look To my Program,That is Very Simple instead of your's
ReplyDeleteplease Comment on this:
main()
{
int a[5];
int i;
printf("Enter Five Number One BY One \n");
for(i=0;i<=4;i++)
scanf("%d",&a[i]);
printf("\n");
printf("Copied elements stored in 2nd array are\n");
for(i=4;i>=0;--i)
printf("%d\t",a[i]);
getch();
}