In: Computer Science
Do a walk-through of the following program segments and determine, in each case, the exact output:
a) int i, j;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= 5; j++)
cout << setw (3) << i;
cout << endl;
}
b) int i, j;
for (i = 1; i <= 5; i++)
{
for (j = (i + 1; j <= 5; j++)
cout << setw(5) << j;
cout << endl;
c) int i, j;
for (i = 1; i <= 5, i++)
{
for (j = 1; j <= i; j++)
cout << setw(3) << j;
cout << endl;
Answer 1:
About • FAQ • Blog • Terms of Use • Contact Us • GDB Tutorial • Credits • Privacy© 2016 - 2019 GDB Online
Run Debug Stop Share Save { } Beautify Language -- select -- C C++ C++ 14 C++ 17 Java Python 3 PHP C# VB HTML,JS,CSS Ruby Perl Pascal R Fortran Haskell Assembly(GCC) Objective C SQLite Javascript(Rhino) Prolog Swift Rust Go Bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i, j;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= 5; j++)
cout << setw (3) << i;
cout << endl;
}
return 0;
}
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
Answer 2:
About • FAQ • Blog • Terms of Use • Contact Us • GDB Tutorial • Credits • Privacy© 2016 - 2019 GDB Online
Run Debug Stop Share Save { } Beautify Language -- select -- C C++ C++ 14 C++ 17 Java Python 3 PHP C# VB HTML,JS,CSS Ruby Perl Pascal R Fortran Haskell Assembly(GCC) Objective C SQLite Javascript(Rhino) Prolog Swift Rust Go Bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i, j;
for (i = 1; i <= 5; i++)
{
for (j = (i + 1); j <= 5; j++)
cout << setw(5) << j;
cout << endl;
}
return 0;
}
2 3 4 5
3 4 5
4 5
5
Answer 3:
About • FAQ • Blog • Terms of Use • Contact Us • GDB Tutorial • Credits • Privacy© 2016 - 2019 GDB Online
Run Debug Stop Share Save { } Beautify Language -- select -- C C++ C++ 14 C++ 17 Java Python 3 PHP C# VB HTML,JS,CSS Ruby Perl Pascal R Fortran Haskell Assembly(GCC) Objective C SQLite Javascript(Rhino) Prolog Swift Rust Go Bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i,j;
for (i = 1; i <= 5;i++)
{
for (j = 1; j <= i; j++)
cout << setw(3) << j;
cout << endl;
}
return 0;
}
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me