Question

In: Computer Science

C++ code please: Write a program that first gets a list of integers from input. The...

C++ code please:

Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates how much to multiply the array by. Finally, print out the entire array with each element multiplied by the last input.

Assume that the list will always contain less than 20 integers.

Ex: If the input is

4 4 8 -4 12 -1

the output is

-4 -8 4 -12

Ex: If the input is

7 0 1 2 3 4 5 6 3

the output is

0 3 6 9 12 15 18

Solutions

Expert Solution

Below is the code in C++ for the above question:

#include<iostream>
using namespace std;

int main(){
   // size of the list of integers
   int n;
   // getting size of list of integers as user input.
   cin >> n;
  
   // array to store the list of integers.
   int ar[n];
  
   // getting list of integer and storing it in the array.
   for(int i=0;i<n;i++)
       cin >> ar[i];
  
   // variable multiplier
   int multiplier;
   // getting multiplier as user input.
   cin >> multiplier;
  
   // multiplying every integer of array by the multiplier
   for(int i=0;i<n;i++)
       ar[i] *= multiplier;
  
   // displaying the list of integers
   for(int i=0;i<n;i++)
       cout << ar[i] << " ";
}

Refer to the screenshot attached below to better understand the code and indentation:


Output:



If this answer helps you then please upvote,
for further queries comment below.
Thank you.


Related Solutions

Write a program that first gets a list of integers from input. The input begins with...
Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain fewer than 20 integers. That list is followed by two more integers representing lower and upper bounds of a range. Your program should output all integers from the list that are within that range (inclusive of the bounds). For coding simplicity, follow each output integer by a space,...
Write a program that first gets a list of 5 integers from input. Then, get another...
Write a program that first gets a list of 5 integers from input. Then, get another value from the input, and output all integers less than or equal to that value. Ex: If the input is 50 60 140 200 75 100, the output is: 50 60 75 For coding simplicity, follow every output value by a space, including the last one. Then, output a newline. Such functionality is common on sites like Amazon, where a user can filter results....
CORAL Language Only: Write a program that first gets a list of six integers from input....
CORAL Language Only: Write a program that first gets a list of six integers from input. The first five values are the integer list. The last value is the upper threshold. Then output all integers less than or equal to the threshold value. Ex: If the input is 50 60 140 200 75 100, the output is: 50 60 75 For coding simplicity, follow every output value by a space, including the last one. Such functionality is common on sites...
In python write a program that gets a list of integers from input, and outputs non-negative...
In python write a program that gets a list of integers from input, and outputs non-negative integers in ascending order (lowest to highest). Ex: If the input is: 10 -7 4 39 -6 12 2 the output is: 2 4 10 12 39 For coding simplicity, follow every output value by a space. Do not end with newline
Write a C program whose input is two integers, and whose output is the first integer...
Write a C program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. For coding simplicity, output a...
write a program named Combinations.java that gets user input for two integers n and k, then...
write a program named Combinations.java that gets user input for two integers n and k, then computes and displays the value of n choose k using the efficient method of equation. you may assume that the user's input makes sense (i.e, n and k are non negative, and n is at least k). your code should work for any reasonably small non- negative values of n and k, including zero.
Code is in C Write a program that reads integers from stdin. Once it reaches the...
Code is in C Write a program that reads integers from stdin. Once it reaches the * end of the input, it prints the smallest absolute value among those * of the numbers it read. * * For example, if * 4, 6 -3, 3, -2, 13, -4 * are read from stdin, the program should print 2. * * If the end of file is reached before any integer is seen, the * number printed should be INT_MAX (defined...
Write code to read a list of song names and durations from input. Input first receives...
Write code to read a list of song names and durations from input. Input first receives a song name, then the duration of that song. Input example: Time 424 Money 383 quit. #include <iostream> #include <string> #include <vector> using namespace std; class Song { public: void SetNameAndDuration(string songName, int songDuration) { name = songName; duration = songDuration; } void PrintSong() const { cout << name << " - " << duration << endl; } string GetName() const { return name;...
Write a C++ program to read in a list of 10 integers from the keyboard. Place...
Write a C++ program to read in a list of 10 integers from the keyboard. Place the even numbers into an array called even, the odd numbers into an array called odd, and the negative numbers into an array called negative. Keep track of the number of values read into each array. Print all three arrays after all the numbers have been read. Print only the valid elements (elements that have been assigned a value). a. Use main( ) as...
(C++) Write a program that reads a list of integers from the keyboard and print out...
(C++) Write a program that reads a list of integers from the keyboard and print out the smallest number entered. For example, if user enters 0 3 -2 5 8 1, it should print out -2. The reading stops when 999 is entered.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT