#include <iostream> #include <iomanip> using namespace std; // create a function
ID: 3669416 • Letter: #
Question
#include <iostream>
#include <iomanip>
using namespace std;
// create a function to print only the contents of the odd subscripts
// of array x; the numbers must be printed vertically on the screen.
void print_arrayx(
{
// use a for loop for printing
for (int i =
}
int main()
{
// declare an array x with 40 subscripts
int x ;
//initialize the contents of the even subscripts of x to a zero
// and the odd subscripts of x to one. Use the start of the for loop below.
// x[0] = 0, x[1] = 1, x[2] = 0, x[3] = 1 . . . . . .
for(int i =
// call the function print_arrayx and pass the array x to the function
// create a for loop that will print the first 20 elements of the array.
return 0;
}
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
// create a function to print only the contents of the odd subscripts
// of array x; the numbers must be printed vertically on the screen.
void print_arrayx(int x[],int n)
{
// use a for loop for printing
for (int i = 0 ;i<n; i++)
if(i%2==1)
cout<<x[i]<<endl;
}
int main()
{
// declare an array x with 40 subscripts
int x[40];
//initialize the contents of the even subscripts of x to x zero
// and the odd subscripts of x to one. Use the start of the for loop below.
// x[0] = 0, x[1] = 1, x[2] = 0, x[3] = 1 . . . . . .
for(int i = 0 ;i<40;i++)
{
if(i%2==1)
x[i] = 1;
else
x[i] = 0;
}
// call the function print_arrayx and pass the array x to the function
print_arrayx(x,40);
// create a for loop that will print the first 20 elements of the array.
for(int i=0;i<20;i++)
cout<<x[i]<<" ";
cout<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.