Question

•Write a program to read 10 numbers and print them in reverse order. Modify your program to work for N numbers given by the u•Write a java program to read 10 numbers and print them in reverse order. Modify your program to work for N numbers given by the user Extend your program to find the average of these numbers Extend your program to find the smallest number of these numbers Extend your program to find the largest number of these numbers

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

a) Program to read 10 numbers and print in reverse order:


#include <iostream>
using namespace std;

int main()
{
  
int a[10];
cout<<"Enter 10 numbers: "<<endl;
  
for(int i=0; i<10; i++)
{
cin>>a[i];
}
  
cout<<"Reverse order: ";
for(int i=9; i>=0; i--)
{
cout<<a[i]<<" ";
}
cout<<endl;
  
  

return 0;
}

Output:

Enter 10 numbers: 10 Reverse order: 10 9 8 7 6 5 4 3 2 1

b) Modification for N numbers by user:


#include <iostream>
using namespace std;

int main()
{
int n;
cout<<"Enter the number of numbers you want to enter: ";
cin>>n;
int a[n];
cout<<"Enter numbers: "<<endl;
  
for(int i=0; i<n; i++)
{
cin>>a[i];
}
  
cout<<"Reverse order: ";
for(int i=n-1; i>=0; i--)
{
cout<<a[i]<<" ";
}
cout<<endl;
  
  

return 0;
}

Output:

Enter the number of numbers you want to enter: 5 Enter numbers: Reverse order: 5 4 3 2 1

c) Extended program to find average of these numbers:


#include <iostream>
using namespace std;

int main()
{
int n;
cout<<"Enter the number of numbers you want to enter: ";
cin>>n;
int a[n];
cout<<"Enter numbers: "<<endl;
  
for(int i=0; i<n; i++)
{
cin>>a[i];
}
  
cout<<"Reverse order: ";
  
float avg=0.0;
  
for(int i=n-1; i>=0; i--)
{
cout<<a[i]<<" ";
avg = avg + (float)a[i];
}
  
avg = avg/(float)n;
  
cout<<"Average: "<<avg<<endl;
cout<<endl;
  
  

return 0;
}


Output:

Enter the number of numbers you want to enter: 5 Enter numbers: Reverse order: 3 2 4 3 2 Average: 2.8

d) Extended program for smallest number:

#include <iostream>
using namespace std;

int main()
{
int n;
cout<<"Enter the number of numbers you want to enter: ";
cin>>n;
int a[n];
cout<<"Enter numbers: "<<endl;
  
for(int i=0; i<n; i++)
{
cin>>a[i];
}
  
cout<<"Reverse order: ";
  
float avg=0.0;
  
for(int i=n-1; i>=0; i--)
{
cout<<a[i]<<" ";
avg = avg + (float)a[i];
}
  
avg = avg/(float)n;
  
cout<<endl;
  
cout<<"Average: "<<avg<<endl;
  
int min=a[0];
  
for(int i=0; i<n; i++)
{
if(a[i]<min)
{
min=a[i];
}
}
cout<<"Smallest number: "<<min<<endl;
  
  
  
  

return 0;
}

Output:

Enter the number of numbers you want to enter: 5 Enter numbers: 32 Reverse order: 2 32 4 3 2 Average: 8.6 Smallest number: 2

e) Extended program for largest number:


#include <iostream>
using namespace std;

int main()
{
int n;
cout<<"Enter the number of numbers you want to enter: ";
cin>>n;
int a[n];
cout<<"Enter numbers: "<<endl;
  
for(int i=0; i<n; i++)
{
cin>>a[i];
}
  
cout<<"Reverse order: ";
  
float avg=0.0;
  
for(int i=n-1; i>=0; i--)
{
cout<<a[i]<<" ";
avg = avg + (float)a[i];
}
  
avg = avg/(float)n;
  
cout<<endl;
  
cout<<"Average: "<<avg<<endl;
  
int min=a[0];
  
for(int i=0; i<n; i++)
{
if(a[i]<min)
{
min=a[i];
}
}
cout<<"Smallest number: "<<min<<endl;
  
int max=a[0];
  
for(int i=0; i<n; i++)
{
if(a[i]>max)
{
max=a[i];
}
}
cout<<"Largest number: "<<max<<endl;
  
  
  
  

return 0;
}

Output:

Enter the number of numbers you want to enter: 5 Enter numbers: Reverse order: 11 2 4 3 2 Average: 4.4 Smallest number: 2 Lar

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

Add a comment
Know the answer?
Add Answer to:
•Write a java program to read 10 numbers and print them in reverse order. Modify 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
  • Write a C PROGRAM that will read in 10 floating-point numbers from the keyboard and load...

    Write a C PROGRAM that will read in 10 floating-point numbers from the keyboard and load them into an array. Add up all the values and store the answer in a variable. Find the largest and smallest number in the array. Put each into its own variable. Print to the screen the sum, largest value, and smallest value. Copy the array to a second array in reverse order. Print out the second array. Read in 20 integer numbers, all in...

  • Write a java program that will print if n numbers that the user will input are...

    Write a java program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times asking for an integer...

  • 1- Write a program to read 10 numbers and find the average of these numbers. Use...

    1- Write a program to read 10 numbers and find the average of these numbers. Use a while loop to read these numbers and keep track of input numbers read. Terminate the while loop with a sentinel value. 2- Now modify the program to find the maximum of these numbers as well. The program should print the number of elements read as input and run until -1 is entered. (-1 is the sentinel that terminates the loop and the program)...

  • Write a java program making use of methods that finds the smallest of any three numbers...

    Write a java program making use of methods that finds the smallest of any three numbers that the user inputs. You must use JoptionPane to input the three numbers. A first method must be called and used to develop logic to find the smallest of the three numbers. A second method must be used to print out that smallest number found.

  • Flowchart Question 1. Draw a flowchart to read five numbers and print the second maximum 2....

    Flowchart Question 1. Draw a flowchart to read five numbers and print the second maximum 2. Draw a flowchart to read five numbers and then order them from smallest number to largest number. 3. Draw a flowchart to read five numbers and then order thenm from smallest number to largest number and display the second maximum.

  • Flowchart Question 1. Draw a flowchart to read five numbers and print the second maximum 2....

    Flowchart Question 1. Draw a flowchart to read five numbers and print the second maximum 2. Draw a flowchart to read five numbers and then order them from smallest number to largest number. 3. Draw a flowchart to read five numbers and then order thenm from smallest number to largest number and display the second maximum.

  • Q1. CLO: (5 points) Write a java program that reads 10 words from the keyboard then...

    Q1. CLO: (5 points) Write a java program that reads 10 words from the keyboard then place them in an array. Display the array elements in reverse order, and then count and print the number of times a word appears in that array. The user shall insert the word from the keyboard.

  • In the Java language APCS Sorting Numbers Lab Write a program that reads in 3 floating-point...

    In the Java language APCS Sorting Numbers Lab Write a program that reads in 3 floating-point numbers (decimal numbers) and prints the three numbers in sorted order from smallest to largest. In your main method, create a scanner and get the 3 numbers from the user. Create a separate method called sort that accepts the 3 numbers prints them in the appropriate order. Sample Run#1 Please enter first number: 4 Please enter second number: 9 Please enter third number: 2.5...

  • Write a java program to print all the prime numbers below a certain given number. A...

    Write a java program to print all the prime numbers below a certain given number. A prime number is defined as a number that can only be divided by 1 and itself. Requirements: 1. Accept the upper limit from the user as an integer. 2. You can assume the user input will be positive and smaller than INT MAX 3. Go from 1 to the number. If you happen to find a number that is prime, print it. The input...

  • In Java please. 2. Create a stack class MyStack2 that extends ArrayList. Write a test program...

    In Java please. 2. Create a stack class MyStack2 that extends ArrayList. Write a test program that reads a number of strings from the user then displays them in reverse order. 3. Modify your code in (2) so that MyStack become a generic class (i.e. MyStack).

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