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
Please write code in C, thank you. Write a program that reads a list of integers,...
Please write code in C, thank you. Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: all even Ex: If the input is: 5 1 3 5 7 9...
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.
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;...
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...
C++ Write a program that reads in a list of 10 names as input from a...
C++ Write a program that reads in a list of 10 names as input from a user and places them in an array. The program will prompt for a name and return the number of times that name was entered in the list. The program should output total number of instances of that name and then prompt for another name until the word done is typed in. For this lab, use the string data type as opposed to char to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT