answersLogoWhite

0


Best Answer

/* Write a C program to reverse the elements of a 1-D array using pointers. */

#include<stdio.h>

#include<conio.h>

#include<process.h>

void REVERSE(int *ptr1, int *ptr2, int n);

void main()

{

int X[30], m, i;

clrscr();

printf("\n\n\n\tEnter the size of Array (Less than 30):");

scanf("%d",&m);

if ((m > 30) (m < 2))

{

printf("\n\n\t\tERROR !!!!!!");

printf("\n\t\tENTER SIZE WITHIN GIEVEN FIELDS....TRY

AGAIN.");

getch();

exit(0);

}

clrscr();

printf("\n\n\n\tEnter the elements of Array :");

for(i=0;i<m;i++)

{

printf("\nElement %d:",i+1);

scanf("%d",&X[i]);

}

REVERSE(X,X,m);

printf("\n\n\n\n\tThe Reversed Array is:\n");

for(i=0;i<m;i++)

printf("\n\t\tElement %d: %d",i+1,X[i]);

getch();

}

void REVERSE(int *ptr1, int *ptr2, int n)

{

int *temp=NULL;

int i;

for(i=0;i<n;i++,ptr2++);

for(i=0,ptr2--; i<(n/2); i++,ptr1++,ptr2--)

{

*temp=*ptr1;

*ptr1=*ptr2;

*ptr2=*temp;

}

}

/************ PROGRAM ENDS ************/

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program to reverse an array elements using dynamic memory allocation?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the use of Reverse String in C program?

The use of the reverse string in C program is used to reverse the letters in the string. An example would be reverse me would be reversed to em esrever.


How do you write a program that outputs a given characters in reverse?

write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)


How do you program a reverse auto loan calculator in JAVA?

In order to program a reverse auto loan calculator in JAVA, you are going to need a lot of experience with JAVA. There are online tutorials that can help you set up with fundamentals of JAVA so that you will be able to create almost any basic program you want.


Write a program in c language to reverse elements of a queue?

There are many ways to reverse the order of the elements in a queue. Provided that you have access to the implementation of the queue, it is of course easy to read the elements from the tail end rather than the front end, thus reversing the elements. However, considering the queue as a black box, and assuming the queue only allows for its characteristic operations (removal of head element, addition to tail), the best method to reverse the elements in a queue to engage a stack. You'd remove the elements from the queue (always reading the head of the queue), and push each element onto the stack. When the queue is empty, you reverse that process: pop each element from the stack until it is empty, and add each element in this order to the end of the queue. Your queue will have the exact same elements as in the beginning, but in reverse order. The exact implementation of this in C, or in any other programming language, is trivial, but the exact source code depends on the implementation of queue and stack containers. Following is pseudocode: Queue&lt;Item&gt; reverse (Queue&lt;Item&gt; queue) { Stack&lt;Item&gt; stack; Item item; while (queue.remove(&amp;item)) { stack.push(item); } while(stack.pop(&amp;item)) { queue.add(item); } return queue; }


How do you reverse the order of the elements in the array?

Start by pointing to each end of the array. Work your way towards the middle of the array, swapping elements as you go. When the pointers meet or pass each other, the array is completely reversed.

Related questions

What is the use of Reverse String in C program?

The use of the reverse string in C program is used to reverse the letters in the string. An example would be reverse me would be reversed to em esrever.


What is the use of reverse ARP?

Reverse ARP is used to Obtain IP address from a Server(responsible for IP addresses allocation) by providing its layer 2 (MAC) address.


A dynamic balance in which the rate of the forward process equals the rate of the reverse process is known as?

equilibrium


Fox pro program to reverse the given number?

reverse programe in fox pro


What is a characteristic of a chemical equilibrium?

Chemical equilibria are dynamic, meaning the forward rate and reverse rate are equal.


How do you write a program that outputs a given characters in reverse?

write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)


How do you Write a C program to reverse an Integer number.?

Reference:cprogramming-bd.com/c_page2.aspx# reverse number


Does Illinois have reverse mortgage?

Yes, the FHA HECM reverse mortgage program is available in all 50 states.


Create a program which accepts a number not less than 10The program prints the reverse of the number?

ten


How can you reverse songs?

Download the program Audacity (it's free) After you have the program installed on your comptuter open a song with the program and hit ctrl+A. Then click effects and click reverse, and wait for it to finish loading. Then you can listen to the reversed version and do other stuff to it.


How to write a program in python to print the reverse of a number?

In python, type the following into a document. NOTE: Sentences following a # symbol are comments, and are not necessary for the program to run. #!/usr/bin/python #This program takes a input from a user and reverses it. number = input("Type a number: ") #This takes input from a user. a = len(number) #This finds the length of the number reverse = "" #This sets the variable reverse to an empty string. for i in number: a = a-1 #The places in a string start from 0. The last value will be the length minus 1.reverse = reverse + number[a] #Makes the number's last digit the new string's first. print("The reverse of", number, "is", reverse + ".") #prints the resulting string. This program will take any sequence of characters and reverse them. The final value is a string, but if an integer is needed, one needs only to add the line reverse = int(reverse) above the print statement. However, this will stop the program from being able to reverse strings, as it is not possible to convert a string to an integer if it is not a number.


Write the program in Linux to find the reverse of any string?

i am sam