Knowee
Questions
Features
Study Tools

Write a C++ program that will input 10 array elements and output the following.elements in original orderelements in reverse ordersmallest element

Question

Write a C++ program that will input 10 array elements and output the following:

  • elements in original order
  • elements in reverse order
  • smallest element
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here’s a C++ program that meets your requirements. It will input 10 elements, output them in their original order, display them in reverse order, and find the smallest element in the array.

#include <iostream>
using namespace std;

int main() {
    const int SIZE = 10;
    int array[SIZE];
    
    // Input 10 array elements
    cout << "Enter 10 elements:" << endl;
    for (int i = 0; i < SIZE; i++) {
        cin >> array[i];
    }

    // Output elements in original order
    cout << "Elements in original order:" << endl;
    for (int i = 0; i < SIZE; i++) {
        cout << array[i] << " ";
    }
    cout << endl;

    // Output elements in reverse order
    cout << "Elements in reverse order:" << endl;
    for (int i = SIZE - 1; i >= 0; i--) {
        cout << array[i] << " ";
    }
    cout << endl;

    // Find the smallest element
    int smallest = array[0];
    for (int i = 1; i < SIZE; i++) {
        if (array[i] < smallest) {
            smallest = array[i];
        }
    }
    
    cout << "Smallest element: " << smallest << endl;

    return 0;
}

Explanation:

  1. The program declares an array of size 10.
  2. It prompts the user to enter 10 elements.
  3. It displays the elements in the order they were entered.
  4. It then displays the elements in reverse order.
  5. Lastly, it finds and outputs the smallest element in the array.

This problem has been solved

Similar Questions

Write a C++ program that will input 10 array elements and output the following.elements in original orderelements in reverse ordersmallest element

Write a program using C language that sorts the 10 rollno,s of your class placed in an array of size 10?Input:87109132546 Output:12345678910

write c program to insert the values at the specific index in the array without using functions

Print Array Elements (Recursive): Write a function that recursively prints the elements of an array in order.

The output of the code will be ____. int i=5; printf(“%d %d %d”, i, i++, ++i); ans. 7 6 5 7 6 6 5 5 7 7 6 7

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.