71.4k views
0 votes
Write a program that reads a list of 10 integers into an array, and outputs those integers in reverse. For coding simplicity, follow each output integer by a space, including the last one. Ex: If the input is: 5 2 4 6 8 10 1 7 3 9 the output is: 9 3 7 1 10 8 6 4 2 5

2 Answers

4 votes

Answer:

integers = []

while True:

number = int(input("Enter integers (Enter negative number to end) "))

if number < 0:

break

integers.append(number)

print ("The smallest integer in the list is : ", min(integers))

print("The largest integer in the list is : ", max(integers))

Step-by-step explanation:

User Agrynchuk
by
5.0k points
5 votes

Answer:

The program to this question can be given as:

Program:

#include <iostream> //header file

using namespace std;

void reverse(int a[], int starting_point, int ending_point) //revers function

{

while (starting_point < ending_point) //loop

{

int temp = a[starting_point];

a[starting_point] = a[ending_point];

a[ending_point] = temp;

starting_point++;

ending_point--;

}

}

void print_Array(int a[]) // print_Array function

{

for (int i = 0; i <=9; i++) //loop for print values

{

cout << a[i] << "\t";

}

}

int main() //main function

{

int a[] = {5,2,4,6,8,10,1,7,3,9}; //array

int n=10;

cout <<"Array is:"<< endl; //message

print_Array(a); //calling function

reverse(a, 0, n-1);

cout <<"Reversed array is:"<< endl; //message

print_Array(a);

return 0;

}

Output:

Array is:

5 2 4 6 8 10 1 7 3 9

Reversed array is:

9 3 7 1 10 8 6 4 2 5

Explanation:

In the above c++ program firstly we define the header file then we declare two functions that are reveres and print_Array. In the reveres function, we pass three parameters that are a[],starting_point,ending_point. in this function we define loop for the reverse array. In this loop, we declare a temp variable that holds the reverse values and passes to array. Then we declare another function print_Array in this function we print array value. At the last we declare the main function in this function we declare an array and initialize array and the call functions.

User Milind Dumbare
by
5.2k points