Question

write a loop to print an array a with pointers backwards. You can use a variable...

write a loop to print an array a with pointers backwards. You can use a variable “size” for array size. write you code in C

Homework Answers

Answer #1
#include <stdio.h>

int main() {
    int n1 = 3, n2 = 9, n3 = 2, n4 = 4, n5 = 1;
    // arr here is an array of pointers
    int *a[5] = {&n1, &n2, &n3, &n4, &n5};

    // printing the array backwards
    int i = 0, size = 5;
    for (i = size - 1; i >= 0; --i) {
        printf("%d ", *a[i]);
    }
    printf("\n");
    return 0;
}

#include <stdio.h>

int main() {
    int a[] = {3, 9, 2, 4, 1}, size = 5;

    // printing the array backwards
    int *p = a + size - 1;
    while (p >= a) {
        printf("%d ", *p);
        p--;
    }
    printf("\n");
    return 0;
}
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
Please, write a loop to print even numbers of an array a with pointers. You can...
Please, write a loop to print even numbers of an array a with pointers. You can use a variable “size” for array size
Create an array named data that can store 100 integers. Write a for loop that loops...
Create an array named data that can store 100 integers. Write a for loop that loops 100 times. Inside the loop store the variable you are using to increment the loop into the current element of the array data. So the array data should have a 0 at index 0, a 1 at index 1, a 2 at index 2, ..., a 99 at index 99.
USE C++ Write a sum() function that is used to find the sum of the array...
USE C++ Write a sum() function that is used to find the sum of the array through pointers. In this program we make use of * operator. The * (asterisk) operator denotes the value of variable. Input: array = 2, 4, -6, 5, 8, -1 Output: sum = 12
Write a code segment to print your name ten times on the screen using a while...
Write a code segment to print your name ten times on the screen using a while loop. Use one variable called count to act as a counter for the loop. Discuss how would you print your name 1000 times on the screen. NOTE: You can either type your code into the text box or upload a document to the discussion board by clicking the "attach" clip at the bottom left of the discussion box.
Be sure to ONLY Program this problem in C You are going to use an array...
Be sure to ONLY Program this problem in C You are going to use an array and a function, and print the values of that array backwards. Here's some guidelines to follow to help you out: 1. Setup your array manually (whichever values you want are ok, with as many as you want, and whichever datatype you prefer. That's all fine). 2. Be sure to call your function by sending two parameters to such function: the array’s length and the...
Write a C++ program to perform the following tasks     a) Declare an integer array of...
Write a C++ program to perform the following tasks     a) Declare an integer array of size 1000.     b) Initialize the array with random values between 1 and 9.     c) Write the code to find and print, how many 1’s occur in the array.
In c++ Write a program that creates a dynamically allocated array to store students’ grades. The...
In c++ Write a program that creates a dynamically allocated array to store students’ grades. The user should be able to decide the size of the array during run time. Write code to fill this array from the keyboard and then print out the values of your array,
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop to initialize the elements (do not initialize the array in the declaration): 10  9   8 7   6   5 4 3   2
Write the following program in MIPS: a) declare an array A of the following numbers: 3,...
Write the following program in MIPS: a) declare an array A of the following numbers: 3, 5, 8, 10, 12, 2, 76, 43, 90, 44 b) declare a variable called size which stores the number of element in array A, that is 10. c) write a subroutine to search for a number stored in an array and return true or false. In C++ the subroutine is as follows: search(array, size, number_To_Search) e.g. search(A, 10, 12) The subroutine should return 0...
Write a Java code snippet with a nested for loop to print five rows of six...
Write a Java code snippet with a nested for loop to print five rows of six random integers between 5 and 10 inclusive.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT