Ask Question

Write a program that reads a list of integers, and outputs those integers in reverse. The input begins with an integer indicating the number of integers that follow. For coding simplicity, follow each output integer by a space, including the last one. Assume that the list will always contain less than 20 integers.

+1
Answers (1)
  1. 15 May, 15:05
    0
    The program to this question as follows:

    Program:

    #include / /header file.

    int main () / /main method.

    {

    const int size = 20; / /define variable.

    int a[size]; / /define array

    int i, n; / /define variable

    printf ("Enter number of elements : "); / /message.

    scanf ("%d", &n); //input size of array.

    printf ("Enter array elements : "); / /message

    for (i = 0; i < n; + +i) / /loop

    {

    scanf ("%d",&a[i]); / /input array elements by user.

    }

    printf ("Reverse order : /n");

    for (i = 0; i < n; + +i) / /loop

    {

    printf ("%d ", a[n-i-1]); / /print elements in reverse order.

    }

    return 0;

    }

    Output:

    Enter number of elements : 5

    Enter array elements : 5

    4

    3

    2

    1

    Reverse order:

    1 2 3 4 5

    Explanation:

    The description of the above program as follows:

    In the program firstly we include the header file and define a method that is "main method" in the method we define variables that are "size, n, i, and a[]". The size variable is used to make a variable constant that means its value will not change in the program. We pass the size variable value to the array and use i variable for loop. We use variable n and a[] for user inputs. In n variable, we input a number of elements to be inserted into an array and a[] we insert all array elements to insert these elements we use for loop. Then we define another for loop in this loop we print all array elements in reverse order.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that reads a list of integers, and outputs those integers in reverse. The input begins with an integer indicating the ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers