Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that prints a selected number from a line 1.First line of input

ID: 3878387 • Letter: W

Question

Write a program that prints a selected number from a line

1.First line of input contains the number of lines to follow

2.First number of each line, n>=2, contains the number of integers that follow in the line

3.Those n integers (each integer >=0; <=1000) follow till the end of the line, and should be stored (except the last one) in an array using index numbers 1…n-1

4.The last integer p (p>=1 & p<=n-1) in the line is the index (starting from 1) of the integer to select from the line and print

Example Input:

4

3 10 1 2

7 3 8 1 5 8 6 4  

4 2 5 1 1

5 3 9 1 6 3

Correct output:

1

5

2

1

Explanation / Answer

#include <iostream>

using namespace std;

int main()
{
int n,var,num[100],index;
//Entering the size of Input.
cin>>n;
for(int i=0;i<n;i++)
{
cin>>var;
//Placing first n-1 elements in an array called "num[]"
for(int j=1;j<var;j++)
{
cin>>num[j];
}
//Entering the last element of line(index number)
cin>>index;
cout<<num[index];
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote