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
Answers
Answered by
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
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
Similar questions
Political Science,
8 months ago
English,
8 months ago
Computer Science,
8 months ago
Math,
1 year ago
Math,
1 year ago
English,
1 year ago