Answer to Question #292003 in C++ for George

Question #292003

First read in an input value for variable numVals. The. Read numVals integer from input and output each integer on a newline after the string “position-“

Ex input 2, 80, 45,

output position-80

position-45

#include <iostream>

musing namespace std;


int main() {

Int numVals;

for(int i=0;I<numVals;I++)


1
Expert's answer
2022-01-30T04:43:43-0500
#include <iostream>
using namespace std;

int main() {
    int numVals;
    cin >> numVals;
    for (int i = 0; i < numVals; i++) {
        int val;
        cin >> val;
        cout << "position-" << val << endl;
    }

    //another solution, if needed to enter all numbers and only then output
    /*
    int numVals;
    cin >> numVals;
    int vals[numVals];
    for (int i = 0; i < numVals; i++)
        cin >> vals[i];
    for (int i = 0; i < numVals; i++)
        cout << "position-" << vals[i] << endl;
    */
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog