IN C++ PROGRAM What numerical values would be displayed? const int SIZEARR = 5;
ID: 3930660 • Letter: I
Question
IN C++ PROGRAM
What numerical values would be displayed?
const int SIZEARR = 5;
int a [SIZEARR];
int j, k, n;
n = 5;
for (j = 0; j < n; j++)
a [ j ] = j;
cout << a [ 0 ] << " " << a [ 1 ] << " " << a [ 2 ] << " " << a [ 3 ] << " " << a [ 4 ] << endl;
for ( j = 1; j < n; j++)
a [ j ] = a [ j -1 ];
cout << a [ 0 ] << " " << a [ 1 ] << " " << a [ 2 ] << " " << a [ 3 ] << " " << a [ 4 ] << endl;
Explanation / Answer
Solution.cpp
#include<iostream>//header file for input output function
using namespace std;// it tells the compiler to link std namespace
int main()
{//main function
const int SIZEARR = 5;//variable declaration and assignments
int a [SIZEARR];
int j, k, n;
n = 5;
for (j = 0; j < n; j++)
//for loop
a [ j ] = j;
cout << a [ 0 ] << " " << a [ 1 ] << " " << a [ 2 ] << " " << a [ 3 ] << " " << a [ 4 ] << endl;
for ( j = 1; j < n; j++)//for loop
a [ j ] = a [ j -1 ];
cout << a [ 0 ] << " " << a [ 1 ] << " " << a [ 2 ] << " " << a [ 3 ] << " " << a [ 4 ] << endl;
return 0;
}
output
0 1 2 3 4
0 0 0 0 0