Question

Write a C program to print the elements of an array in reverse order using pointer.

Write a C program to print the elements of an array in reverse order using pointer.

Homework Answers

Answer #1

C Program:

#include<stdio.h>

int main() {

int n, i;

int *p;

printf("\nEnter the size of array : ");

scanf("%d", &n);

int arr[n];

p=&arr[0];

printf("\nEnter %d integers: ",n);

for (i=0;i<n;i++) {

scanf("%d",p);

p++;

}

p=&arr[n-1];

printf("\nReverse of the array is :");

for (i=n-1;i>=0;i--) {

printf("\n%d",*p);

p--;

}

}

if you like the answer please provide a thumbs up.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1) a. Write the C++ program that uses a recursive function to print the elements of...
1) a. Write the C++ program that uses a recursive function to print the elements of a list in reverse order. b. Write the pseudocode for the program.
***C++ CODING*** Write a program for sorting a list of integers in ascending order using the...
***C++ CODING*** Write a program for sorting a list of integers in ascending order using the bubble sort algorithm. Requirements Implement the following functions: Implement a function called readData int *readData( )   The function returns a pointer that points to the locations with integers reading from the file data.txt. arr is a pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers from a file call data.txt into the array...
C programming language. Write a program to print reverse of all the numbers from m to...
C programming language. Write a program to print reverse of all the numbers from m to n using functions with arguments and no return type. The inputs in the program will be m and n variables and need to take these variables as arguments.
Write a recursive C++ program that find the duplicate elements in an array. Your program shouldn't...
Write a recursive C++ program that find the duplicate elements in an array. Your program shouldn't use any sorting or use any additional array.
Create a program that allocates an array of integers, frees them, and then tries to print...
Create a program that allocates an array of integers, frees them, and then tries to print the value of one of the elements of the array. Does the program run? What happens when you use Valgrind on it? Now pass a funny value to free (e.g., a pointer in the middle of the array you allocated above). What happens? Do you need tools to find this type of problem?
Write a program in c++ to Convert an array of inches to an array of centimeters....
Write a program in c++ to Convert an array of inches to an array of centimeters. The program should contain a function called inchesTOcm with three parameters (inches array that contains the values in inches, cm array to save the result in, and an integer variable that defines the length of the array). In the main function: 1. Define an array (inches) of length 3. 2. Initialize the array by asking the user to input the values of its elements....
Write a Java method to print the maximum and minimum value of an array containing elements...
Write a Java method to print the maximum and minimum value of an array containing elements [7,20,29,0,4,30,24,100]
IN C++ Write a program named printStringReverse.cpp to read in a C-Style sting. Print the string...
IN C++ Write a program named printStringReverse.cpp to read in a C-Style sting. Print the string forward and then backward using pointer increment and decrement. Declare the C-Style string as following: char s[50]; Read the string as follows; cin >> s; Write the following code to get the actual number of characters from your string. int count=0; while (s[count] != NULL) { count++; } count contains the actual length of your string since we declared the array to hold a...
C program question: Write a small C program connect.c that: 1. Initializes an array id of...
C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and changing all the entries with the same name as p to...
Reversing an array is a common task. One approach copies to a second array in reverse,...
Reversing an array is a common task. One approach copies to a second array in reverse, then copies the second array back to the first. However, to save space, reversing an array without using a second array is sometimes preferable. Write a code in java that reads in an integer representing the length of the array. Then read in and reverse the given array, without using a second array. If the original array's values are 2 5 9 7, the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT