5. Show the output of each of the following C++ program segments: int j; int one
ID: 3768550 • Letter: 5
Question
5. Show the output of each of the following C++ program segments:
int j;
int one[5], two[10];
for (j = 0; j < 5; j++)
one[j] = 5*j + 3;
cout << “One cntains: “;
for (j = 0; j < 5; j++)
cout << setw(3) << one[j];
cout << endl;
for (j = 0; j < 5; j++)
{ two[j] = 2*one[j] - 1;
two[j + 5] = one[4 - j] – 1 + two [j];
}
cout << “Two cntains: “;
for (j = 0; j < 10; j++)
5. Show the output of each of the following C++ program segments:
int j;
int one[5], two[10];
for (j = 0; j < 5; j++)
one[j] = 5*j + 3;
cout << “One cntains: “;
for (j = 0; j < 5; j++)
cout << setw(3) << one[j];
cout << endl;
for (j = 0; j < 5; j++)
{ two[j] = 2*one[j] - 1;
two[j + 5] = one[4 - j] – 1 + two [j];
}
cout << “Two cntains: “;
for (j = 0; j < 10; j++)
cout << setw(3) << two[j];
cout << endl;
cout << setw(3) << two[j];
cout << endl;
Explanation / Answer
Segment 1 Output:
Segment 2 Output:
One cntains: 3 8 13 18 23
Two cntains: 5 15 25 35 45 27 32 37 42 47
4196400
Segment 1 Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int j;
int one[5], two[10];
for (j = 0; j < 5; j++)
one[j] = 5*j + 3;
cout << "One cntains:";
for (j = 0; j < 5; j++)
cout << setw(3) << one[j];
cout << endl;
for (j = 0; j < 5; j++)
{ two[j] = 2*one[j] - 1;
two[j + 5] = one[4 - j] - 1 + two [j];
}
cout << "Two cntains:";
for (j = 0; j < 10; j++)
return 0;
}
Segment 2 Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int j;
int one[5], two[10];
for (j = 0; j < 5; j++)
one[j] = 5*j + 3;
cout << "One cntains: ";
for (j = 0; j < 5; j++)
cout << setw(3) << one[j];
cout << endl;
for (j = 0; j < 5; j++)
{ two[j] = 2*one[j] - 1;
two[j + 5] = one[4 - j] - 1 + two [j];
}
cout << "Two cntains:";
for (j = 0; j < 10; j++)
cout << setw(3) << two[j];
cout << endl;
cout << setw(3) << two[j];
cout << endl;
return 0;
}
Explanation:
In your code there are special character(") which are to be replaced by ".
Don't forget to include manip.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.