Question

How do you define a triangular two-dimensional array using just vectors, not arrays or pointers? (C++)

How do you define a triangular two-dimensional array using just vectors, not arrays or pointers? (C++)

Homework Answers

Answer #1

#include <iostream>
#include <vector>
using namespace std;

int main(){
   //1st way , store even the zeros
   vector< vector<int> > triang1 = { {1, 0, 0, 0},
                                   {2, 3, 0, 0},
                                   {4, 5, 6, 0},
                                   {7, 8, 9, 1}};
   //2nd way not store zeros
   vector< vector<int> > triang2 = { {1},
                                   {2, 3, },
                                   {4, 5, 6,},
                                   {7, 8, 9, 1}};
                                     
   return 0;
}
                                      

Know the answer?
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
Similar Questions
Class work # 12 / Chapter 6 –> Arrays 3 (two dimensional arrays) Part 1: Create...
Class work # 12 / Chapter 6 –> Arrays 3 (two dimensional arrays) Part 1: Create a 2-by-3 integer array and initialize it with 6 integers of your choice. Using nested for loops, display the contents of the array on the screen Part 2: (Continue on part 1) Display the sum of all the integers in the array that you created in part 1. Create a function Part 3: Create a function that will display the elements of the array...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop to initialize the elements (do not initialize the array in the declaration): 10  9   8 7   6   5 4 3   2
USING JAVA ONLY Merge two 1D arrays into a single array. take one value from each...
USING JAVA ONLY Merge two 1D arrays into a single array. take one value from each array at a time. Sample: array 1: 1,2,3,4,5 array 2: 2,4 new array: 1,2,2,4,3,4,5
Given the existence of two-dimensional array double A[M][N], where M and N are #defined as the...
Given the existence of two-dimensional array double A[M][N], where M and N are #defined as the number of rows and columns, respectively, define a function named sqabsmax that accepts array A as an argument (i.e. input parameter) and returns the square of the maximum absolute value element in A. Use the const qualifier if appropriate. Only show the function definition. Do not write an entire program with a main function. Just write the definition for function sqabsmax.
C++ program that searches a two-dimensional array to find a value(s) (high low equal to). Display...
C++ program that searches a two-dimensional array to find a value(s) (high low equal to). Display results using a function
In C++ You are given two arrays each of which is sorted. Write a method called...
In C++ You are given two arrays each of which is sorted. Write a method called mergeIt that takes the two arrays and merges them into one array. For instance, if you had 5, 9, 11 and 4, 6, 7 then you need to merge it to 4,5,6,7,9,11.
USING JAVA ONLY - THE NEW ARRAY IS NOT JUST THE VALUES IN INCREASING ORDER Merge...
USING JAVA ONLY - THE NEW ARRAY IS NOT JUST THE VALUES IN INCREASING ORDER Merge two 1D arrays into a single array. take one value from each array at a time. The new array takes a value from array 1, than one from array two, and keeps repeating until all values are in the new array. Sample: array 1: 1,2,3,4,5 array 2: 2,4 new array: 1,2,2,4,3,4,5 Sample 2: array 1: is 8,2,4,7,2,6,2 array 2: 4,7,3 new array: 8,4,2,7,4,3,7,2,6,2
Pointers is a difficult concept for many students.  I'm not sure how to make students understand the...
Pointers is a difficult concept for many students.  I'm not sure how to make students understand the concept better. In an attempt to have you try to understand pointers, I'm going to ask you to write a paper that summarizes the chapter (or an online resource) that may help you understand the concept of pointers. Include the following topics in the paper. Include illustrations either from the book, or an online source or your own illustration. Come up with an introduction...
Define the board space for a four-dimensional Tic Tac Toe board? (in C#) What is harder...
Define the board space for a four-dimensional Tic Tac Toe board? (in C#) What is harder creating the data structure you thought of or writing the rules that support it? Give a detailed example. How do you pass a structure or an array to a function? If I declare a variable as follows: int x; please describe how that variable is represented in memory. What does &(x) return? What does *(x) return? What does *(&(x)) return?
Create a function mult_arr which accepts two pointers-to-double as input along with an integer reflecting the...
Create a function mult_arr which accepts two pointers-to-double as input along with an integer reflecting the length of each array. The function should return void. Using pointer arithmetic to access the array elements, compute the element-wise product of the two arrays in-place (the result is stored in the first array). The function should return void. In main, read in two arrays of 10 values from the user following the I/O format seen in the example run below. On a new...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT