Question

Write a C++ program that reads in 6 elements from the keyboard and stores them in an array x[6]. It should then create a second array y[6] that contains the elements from x in reverse order and with the s Tsecond - Tsmallest shown below. A sample run should look like: rocted ITrom it (e.g., Jlast first Tsmallest Vsecond last , etc). The program should finally print out both arrays to screen, in the format Enter 6 array elements: 4 29 12 3 5 Arrays x and y: 9 10 12 7 3 0 5 2

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

#include<iostream>
using namespace std;

int main()
{
int x[6],y[6],i,smallest;
cout<<"Enter 6 array elements : ";


//Accepting values of array x[6]

for(i=0;i<=5;i++)
{
cin>>x[i];
}
cout<<endl;
cout<<"Entered elements of x are : ";

for(i=0;i<=5;i++)
{
cout<<x[i]<<"\t";
}
cout<<endl<<endl;

smallest=x[0];

//finding smallest element of array x[6]

for(i=0;i<=5;i++)
{
if(smallest>x[i])
{
smallest=x[i];
}
}
cout<<"\nSmallest number is "<<smallest<<endl<<endl;

//storing elements of x in y as per given questions

for(i=0;i<=5;i++)
{
y[i]=x[5-i]-smallest;
}

cout<<"\nElements of array y are : ";
for(i=0;i<=5;i++)
{
cout<<y[i]<<"\t";
}
cout<<endl<<endl;
//system("pause");
return 0;
}

CAUsersvusenDesktopDebugiAmtyee Enter 6 array elements 4 29 12 35 Entered elements of x are4 2 12 Smallest number is 2 Elemen

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that reads in 6 elements from the keyboard and stores them in...
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
  • 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 C++, write a complete program that receives a series of student records from the keyboard...

    In C++, write a complete program that receives a series of student records from the keyboard and stores them in three parallel arrays named studentID and courseNumber and grade. All arrays are to be 100 elements. The studentID array is to be of type int and the courseNumber and grade arrays are to be of type string. The program should prompt for the number of records to be entered and then receive user input on how many records are to...

  • Write a program that reads a string from the keyboard and computes the two arrays of...

    Write a program that reads a string from the keyboard and computes the two arrays of integers upperCase, and lowerCase, each of size 26. The first one represents the frequency of upper case letters and the second one represents the frequency of lower case letters in the input string. After computing these arrays, the program prints the frequencies in the following format: The frequency of the letter A= The frequency of the letter B= Assume the input string contains only...

  • Q#1 Write a C++ program that reads n integer values and stores them in an array...

    Q#1 Write a C++ program that reads n integer values and stores them in an array of maximum 20 integers. Read from the user a valid value of n (n should not exceed 20). After reading the n array elements find the maximum and minimum elements.

  • Write a Java program that reads in 5 words from the user and stores these words...

    Write a Java program that reads in 5 words from the user and stores these words in a String array. Then your program needs to print 2 lines of output with the following information: All words are in reverse order (based both on content and order). Every word at an even index of the array (i.e., indices 0, 2, and 4). For example, if user inputs "ABC", "DEF", "TY", "JK", and "WE". Then your program should output the following two...

  • 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...

  • 1) Write a C program that reads a hexadecimal value from the keyboard and then stores...

    1) Write a C program that reads a hexadecimal value from the keyboard and then stores the value into an unsigned char variable. Read two int values p and n from the keyboard, where the values are less than 8. Implement the following commands: S – sets the n bits starting at position p to 11..1 R – resets the n bits starting at position p to 00…0 F – flips the n bits starting at position p to their...

  • write a java program Accept a positive integer n from keyboard and then create an array...

    write a java program Accept a positive integer n from keyboard and then create an array or arraylist containing n random elements within the range [-n,n). Print out the random array or arraylist, and then find out and print out the number of inversions and the maximum subarray (index range of the maximum subarray along with the maximum subarray sum) in the array or arraylist using divide and conquer, respectively. For example, suppose we accept integer 6 from keyboard, then...

  • c++ Write a program that reads 10 marks of type float, store them in an array,...

    c++ Write a program that reads 10 marks of type float, store them in an array, then the program will 4 determine the number of marks greater than the average. Write a program that reads 10 marks, store them in an array, then the program will print the .5 array in reverse order.

  • Write a complete Java program in a file caled Module1Progrom.java that reads all the tokens from...

    Write a complete Java program in a file caled Module1Progrom.java that reads all the tokens from a file named dota.txt that is to be found in the same directory as the running program. The program should ignore al tokens that cannot be read as an integer and read only the ones that can. After reading all of the integers, the program should print all the integers back to the screen, one per line, from the smalest to the largest. For...

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