Question

Part 2) write a C++ program that declares a 2 dimensional array: int CSIIAssign3 [10][12]; Initialize...

Part 2) write a C++ program that declares a 2 dimensional array: int CSIIAssign3 [10][12]; Initialize your array using a text file, user input or assign value while declaring the array, you can choose the method. Then,

a. Write a loop to print first row of the array on one line, using cout.

b. Write a loop to print first column of the array on one line, using cout.

c. Write a loop to print first five rows of the array on one line, using cout, each line in a single output line.

d. Write a loop to print the entire array backward and upside down, so that the last index appears first, with the last column on the left. Here is an example: {2,3,4} {8,6,9} You want to print it as: {9,4} {6,3} {8,2}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans:-

Code:-

#include<iostream>//for input output operations
using namespace std;
int main()
{//declare array of size 10rows * 12 cols
int CSllAssign3[10][12];
int v=0;//used for assign
//initialise the array from 0 to 119
for(int i=0;i<10;i++){//for each row of matrix
for(int j=0;j<12;j++){//for each column of matrix for particular row
CSllAssign3[i][j]=v;
v++;//increment value of v
}
}

//print the array
for(int i=0;i<10;i++){
for(int j=0;j<12;j++){
cout<<CSllAssign3[i][j]<<" ";//print the matrix element corresponding to ith row jth column

}cout<<"\n";// change the line after every row
}


//-----------------------------------------------------------------------------------------------
cout<<"\n\n\n\n";//a) print first row
for(int j=0;j<12;j++)//for each column
{
cout<<CSllAssign3[0][j]<<" ";//print first row element i.e 0 index for each column
}
//------------------------------------------------------------------------------------------------
cout<<"\n\n\n\n";//b) print first column
for(int i=0;i<10;i++)//for each row
{
cout<<CSllAssign3[i][0]<<" ";//print first column element i.e 0 index for each row
}
//------------------------------------------------------------------------------------------------
cout<<"\n\n\n\n";//c) print first 5 rows in single line
for(int i=0;i<5;i++){//for first five rows i.e 0 to 4
for(int j=0;j<12;j++){//for each column
cout<<CSllAssign3[i][j]<<" ";//print the element

}
}
//------------------------------------------------------------------------------------------------
cout<<"\n\n\n\n";//d) print matrix backward and upside down
for(int j=11;j>=0;j--){//starting from last column to first column. print element of particular column from last row to first row
for(int i=9;i>=0;i--){//starting from last column to first column
cout<<CSllAssign3[i][j]<<" ";

}
cout<<"\n";
}
return 0;}

Output:-

There are 5 parts of output, first is the matrix and the rest 4 corresponding to each part.

Please like the answer if it is helpful to you.

Add a comment
Know the answer?
Add Answer to:
Part 2) write a C++ program that declares a 2 dimensional array: int CSIIAssign3 [10][12]; Initialize...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write the line that declares a two-dimensional array of strings named chessboard. That is, how would...

    Write the line that declares a two-dimensional array of strings named chessboard. That is, how would I declare a two-dimension array of strings that is called chessboard? You would declare a String array by saying " String []" correct? Now that's just a single array. How can I make that a two-dimension array? And how would I name it chessboard? Write the line that declare and creates a two-dimensional array of chars, tictactoe, with 3 rows, each with 3 elements...

  • Write a java code that Declares and initialize a two-dimensional int array named grades. It should...

    Write a java code that Declares and initialize a two-dimensional int array named grades. It should have 10 rows and 6 columns where it stores the values and then calculates the average of all the elements in the grades array that you have declared

  • Using Java. Write a program that creates a “triangular” two-dimensional array A of 10 rows. The...

    Using Java. Write a program that creates a “triangular” two-dimensional array A of 10 rows. The first row has length 1, the second row has length 2, the third row has length 3, and so on. Then initialize the array using nested for loops so that the value of A[i][j] is i+j. Finally, print out the array in a nice triangular form.

  • Refer to the following array definition for questions 1 & 2 int numberArray[9)[11] 1. Write a...

    Refer to the following array definition for questions 1 & 2 int numberArray[9)[11] 1. Write a statement that assigns 145 to the first column of the first row of this array. 2. Write a statement that assigns 18 to the last column of the last row of this array. values is a two-dimensional array of floats, with 10 rows and 20 columns. Write code that sums all of the elements in the array and stores the sum in the variable...

  • Write a C++ program: Declares an array named numberList with 50 components of the type int....

    Write a C++ program: Declares an array named numberList with 50 components of the type int. Initialize the array so that the first 25 components are equal to the square of the counter (or index) variable and the last 25 components are equal to 1, 2, 3, … , 25. Output the array so that exactly ten elements per line are printed.

  • create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array...

    create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...

  • Write a program that performs the following operations on a one dimensional array with 50 unsigned...

    Write a program that performs the following operations on a one dimensional array with 50 unsigned integers. The main program will initialize the array, print the array values to the screen and then call a function that will determine and print the maximum and minimum values. •Declare the array and any other variables. •Use a loop to initialize the array with 50 random integer values between 0 and 99 using the rand() function. (number = rand() % 100;) •Using cout...

  • Submit two C++ files: 1. Write a C++ program that declares an array alpha of 50...

    Submit two C++ files: 1. Write a C++ program that declares an array alpha of 50 components of type double. Initialize the array so that the first 25 components are equal to the square of the index variable, and the last 25 components are equal to three times the index variable. Output the array so that 10 elements per line are printed. 2. Write a program that prompts the user to input a string and outputs the string in uppercase...

  • C++ Program - Arrays- Include the following header files in your program:     string, iomanip, iostream Suggestion:...

    C++ Program - Arrays- Include the following header files in your program:     string, iomanip, iostream Suggestion: code steps 1 thru 4 then test then add requirement 5, then test, then add 6, then test etc. Add comments to display assignment //step 1., //step 2. etc. This program is to have no programer created functions. Just do everything in main and make sure you comment each step. Create a program which has: 1. The following arrays created:                 a. an array...

  • Three C Code Questions: 5. Write a C program that declares an array of 10 strings,...

    Three C Code Questions: 5. Write a C program that declares an array of 10 strings, each of max length 50 characters, and then reads an entire line of text from the keyboard into each string. 6. Write C code that finds the longest name in this array of strings that you read in Q5. Hint: find the position of the longest string, not the string itself. 7. Write a C program that creates a 4 x 6 two dimensional...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT