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 fewer than 20 integers.

Respuesta :

Answer:

The program to this question can be described as follows:

Program:

#include<stdio.h> //defining header file

int main() //defining main method

{

const int total_number= 20; //defining integer constant variable

int a[total_number],i; //defining integer array and variable  

printf("Enter total number, that you want to insert in list: "); //message  

scanf("%d",&a[0]); //input value by user

printf("Input list: "); //message

for(i=1;i<=a[0];i++) // loop for input value

{

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

}

printf("List in reverse order:\n");

for(i=a[0];i>0;i--) //loop for print list in reverse order

{

printf("%d ",a[i]); //print value

}

return 0;

}

Output:

Enter total number, that you want to insert in list: 5

Input list: 6

4

2

8

1

List in reverse order:

1 8 2 4 6  

Explanation:

In the above C language program, three integer variable "total_number, a[], and i " is declared, in which total_number is a constant variable, that holds value 20, which is passed in an array, in array first element we input the total number of the list.

  • In the next step, an array variable is used, that uses for loop to input number in list.  
  • Then another for loop is declared that prints the array value in its reverse order, with a white space.