Question

In C++: Write a program that asks the user for an array of X numbers. Your...

In C++:

Write a program that asks the user for an array of X numbers.

Your program moves the largest number all the way to the right, and then shows it to the user.

Hint: Use a loop to swap X times, but only swap if the number on the left is bigger than the number on the right.

Sample Run:

How many numbers would you like to enter? 6

Please enter number 1: 10

Please enter number 2: 8

Please enter number 3: 3

Please enter number 4: 5

Please enter number 5: 2

Please enter number 6: 9

The largest number is: 10

New List: 8, 3, 5, 2, 9, 10

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int main() {
   int X, tmp;
   cout<<"How many numbers would you like to enter? ";
   cin>>X;
   
   int* arr = new int(X);
   
   for(int i = 0;i<X;i++){
      cout<<"Please enter number "<<(i+1)<<": ";
      cin>>arr[i];
   }
   
   for(int i = 0;i<X-1;i++){
      if(arr[i] > arr[i+1]){
         tmp = arr[i];
         arr[i] = arr[i+1];
         arr[i+1] = tmp;
      }
   }
   
   cout<<"New List: ";
   for(int i = 0;i<X;i++){
      if(i==0){
         cout<<arr[i];
      }
      else{
         cout<<", "<<arr[i];
      }
   }
   
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
In C++: Write a program that asks the user for an array of X numbers. Your...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (C programing, Not C++) Write a program in C that asks the user to input 10...

    (C programing, Not C++) Write a program in C that asks the user to input 10 numbers. Store these numbers in an array. Then ask the user to input a single number. Your program should execute a linear search on the array, trying to find that number. If the number exists in the array, have the program print out which position/element the number was found at. If the target number is not in the array, have the program print out...

  • Write a program that asks the user to input 10 integers of an array. The program...

    Write a program that asks the user to input 10 integers of an array. The program then inserts a new value at position (or index) given by the user, shifting each element right and dropping off the last element. For example, in the sample input/output below, the program will insert the value 30 at index 3. All the previous numbers of the array starting from position 3 (i.e., 7 1 20 9 23 8 22 will be shifted one position...

  • write a program code that asks the user how many numbers they wish to find the...

    write a program code that asks the user how many numbers they wish to find the statistics of and then asks the user to enter those numbers. The program must then calculate and display the average variance and standard deviation of the numbers entered by the user. the program code must -ask three user how many numbers they wish to find the statistics of -ask the user to enter those numbers and store them in an array - use a...

  • Write a C program that asks the user to enter two real numbers. Then your program...

    Write a C program that asks the user to enter two real numbers. Then your program displays a menu that asks the user to choose what arithmetic operation to be done on those numbers. Depending on the user's entry, the program should display the result to the screen. The sample runs below show what should be done to the numbers entered by the user. Your program should run exactly like shown in the sample runs. make your code run as...

  • Design a program that asks the user to enter a series of 20 numbers. The program...

    Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in the array and then display the following data: The lowest number in the array The highest number in the array The total of the number in the array The average of the numbers in the array PLEASE GIVE THE PSEUDOCODE AND CODE IN C PROGRAMMING

  • Write a program that asks the user to enter number, and displays all the numbers that...

    Write a program that asks the user to enter number, and displays all the numbers that are multiples of 2 and 5 smaller than or equal to the number entered by the user. Hint: A number n is a multiple of 2 if the remainder of the division of n by 2 is equal to zero. Your program should have an output similar to the following: Please enter a number: 50 The multiples of 2 and 5 less than or...

  • Using python Problem 6 (10 points). Write a program which asks the user to enter a...

    Using python Problem 6 (10 points). Write a program which asks the user to enter a number and prints its multiplication table upto 10. Sample program output: Please enter a number: 9 9 X 1 = 9 9 X 2 = 18 9 X 3 = 27 9 X 4 = 36 9 X 5 = 45 9 X 6 = 54 9 X 7 = 63 9 X 8 = 72 9 X 9 = 81 9 X 10...

  • Write a C++ program that will have a predefined array and then asks the user to...

    Write a C++ program that will have a predefined array and then asks the user to enter an integer value call it number . Then write the following functions to display:  All values larger than number

  • Write a c++ program that reads numbers from the user, and prints a table showing how...

    Write a c++ program that reads numbers from the user, and prints a table showing how many times each digit appears in each number. The user should be able to enter more than one number to be tested for repeated digits. The program should terminate when the user enters a number that is less than 0. Here is a sample output: Enter a number (-1 to end this loop): 41271092 Digit: 0 1 2 3 4 5 6 7 8...

  • LANGUAGE: JAVA Sorting an array: 2. Write a program that asks the user for 5 numbers...

    LANGUAGE: JAVA Sorting an array: 2. Write a program that asks the user for 5 numbers and stores them in an array called data. Then call a method that accepts the array as an argument, sorts the array in ascending order and prints out the original AND sorted array (Hint: The method does not return anything in this case, so it should be set to void).

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT