Fill in code to have following outout: abcde fghij klmno pqrst uvwxy code: #incl
ID: 3574362 • Letter: F
Question
Fill in code to have following outout:
abcde
fghij
klmno
pqrst
uvwxy
code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string characters = "abcdefghiklmnopqrstuvwxy";
vector< vector<char> > grid;
for (int i = 0; i < 5; i++) {
vector<char> temp;
for (int j = 0; j < 5; ++j) {
}
grid.push_back(temp);
}
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 5; ++j) {
cout << grid.at(i).at(j);
}
}
Explanation / Answer
//c++ code
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string characters = "abcdefghijklmnopqrstuvwxy";
vector< vector<char> > grid;
for (int i = 0; i < characters.size(); i=i+5)
{
vector<char> temp;
for (int j = i; j < (i+5); ++j)
{
temp.push_back(characters[j]);
}
grid.push_back(temp);
}
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 5; ++j)
{
cout << grid.at(i).at(j);
}
cout << endl;
}
return 0;
}
/*
output:
abcde
fghij
klmno
pqrst
uvwxy
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.