Question

How do I write a while loop with a conditional statement designed to read through a...

How do I write a while loop with a conditional statement designed to read through a vector of vectors?
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<vector<int> > myvect{ { 1, 2, 3, 4, 5 }, 
                               { 6, 7}, 
                               { 8, 9, 10, 11, 12, 13 },
                               {14} }; 
  
        for(int i=0; i<myvect.size(); i++) {
                for(int j=0; j<myvect[i].size(); j++) {
                        cout << myvect[i][j] << " ";

                        // you can check the myvect[i][j]
                        // which is the number on ith row
                        // and jth column, we are reading and printing it.

                }
                cout << endl;
        }
}

I have shown the code, which you can use to traverse a vector of vector.. let me know if you have other issues related to this..

Add a comment
Know the answer?
Add Answer to:
How do I write a while loop with a conditional statement designed to read through a...
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
  • How do I write this code from while loop to for loop? (this is the whole...

    How do I write this code from while loop to for loop? (this is the whole code) NOTE: do not add any import other than: import java.util.ArrayList; import java.util.Collection;(collection not collections) import java.util.List; import java.util.Set; import java.util.TreeSet; import java.util.HashSet; code: public static int frequency(Collection values, int target) { var iter = values.iterator(); int app = 0; while (iter.hasNext()) { if(iter.next() == target) { app++; } } return app; } public static boolean isSorted(List list) { var iter = list.listIterator(); int...

  • Matlab ( True or False questions ) Statement while - end does not need a "conditional...

    Matlab ( True or False questions ) Statement while - end does not need a "conditional expression" Given a recursive problem, there is only one way to program a while - end loop A while - end loop will run forever unless one statement alters the "conditional expression" The loop while -9 == -9 end will not run forever Counting by one is always done by statement i = i + 1 Dividing 1 by 27 can be accomplished by...

  • in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...

    in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){                 sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() {    int score, highest;             //missing portion of the program             return 0;    } 1(c). Find the missing portion of the following code, so the...

  • Question 2 (d) Write equivalent code to the one shown below by replacing the while loop...

    Question 2 (d) Write equivalent code to the one shown below by replacing the while loop with a for loop while x <= 15 x=x+1; end [4 marks] (e) Write the small program from the previous question using a single line of code with vector operations. [2 marks] (f) Write a MATLAB script that uses a loop to print the contents of two vectors interleaved in to one vector. Assume both vectors are the same length. For example, if A...

  • java program QUESTION 2: 1. Write a do-while loop that asks the user to select a...

    java program QUESTION 2: 1. Write a do-while loop that asks the user to select a task from the following menu to continue: 1. Option 1 2. Option 2 3. Option 3 4. Option 4 5. Exit Read the selection from the keyboard then write the switch statement: For option 1, display the message "Do the option 1" For option 2, display the message "Do the option 2" For option 3, display the message "Do the option 3" For option...

  • Write a program that uses a while loop to read in a series of test scores,...

    Write a program that uses a while loop to read in a series of test scores, then calculates the average. Control the number of repetitions by using a sentinel value. In python ty

  • Write a C++ program. Using the while loop or the do – while loop write a...

    Write a C++ program. Using the while loop or the do – while loop write a program that does the following: Calculate the average of a series of homework grades (0 - 100) entered one at a time. In this case the lowest score will be dropped and the average computed with the remaining grades. For example suppose you enter the following grades: 78, 85, 81, 90, 88, 93 and 97.The average will be computed from the 6 grades 85,...

  • How many times is the loop body of the while statement executed?

     How many times is the loop body of the while statement executed? a. once b. forever C. 49 times d. 50 times e. until a number 50 or larger is entered The value stored in variable s at the end of the execution of the loop could best be described as: a. the average of the numbers scanned b. the sum of the numbers scanned c. the largest of the numbers scanned d. how many numbers were scanned e. the sentinel value The value stored in variable z at the end of the...

  • Write a complete C++ program using a while loop to read a list of integers ending...

    Write a complete C++ program using a while loop to read a list of integers ending with the integer 999. Count and output the number of integers in the list that are greater than 500. If there is no integer in the list that is greater than 500. output (only once) the message that "No integer in the list is greater than 500". Do not use functions.

  • How do you write a while loop that ends after the exact same word has been...

    How do you write a while loop that ends after the exact same word has been entered twice by the user?

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