Computer Science, asked by GauravKumarRai, 1 year ago

Write a function which accept an array and returns an array which contains the elements in the reverse order.


ananya071: Elements are no. or char or string
GauravKumarRai: string
DeepuRawat: in which language java or c
GauravKumarRai: java
DeepuRawat: ok
GauravKumarRai: so when will you give the answer please do fast
ananya071: function or function prototype
GauravKumarRai: function
ananya071: ohk

Answers

Answered by yasas
0
#include<stdio.h>
void main()
{
   int a[5],b[5],i,j;
   clrscr();
   printf("enter any numbers\n");
   for(i=0;i<5;i++)
     scanf("%d",&a[i]);
   for(i=0;i<5;i++)
    {
       for(j=4;j>=0;j--)
          {
               b[i++]=a[j];
          }
    }
    printf("the reverse order is\n");
     for(i=0;i<5;i++)
       printf("%d\n",b[i]);
     getch();
}
i have chosen numbers range upto 5 you can increase it as per your requirement the output will be like
enter any 5 numbers
1
2
3
4
5
the reverse order is
5
4
3
2
1

DeepuRawat: you don't need to use 2 arrays u can do so with only one just place the loop in reverse order for(i=5;i>=1;i--) and peint the value of array it will show all in reverse
yasas: actually when you do that you are just trying to display the required output but in the above case in the first array you will have the input and the second array contains the reverse of it programs can be written to given the essential outputs in many ways but not all are efficient thank you for the advise and it works too
Similar questions