Question

Write a program that (use C++) if u can use or <iostream> or <stdio.h> or both .

  1. Creates a 5x4 array.
  2. Creates a function that reverses all the rows and columns using loops and stores the result in a different array.
  3. In the main function print both arrays.

Example: Input Array 100 101 102 103 110 111 112 113 120 121 122 123 130 131 132 133 140 141 142 143 Output Array 143 142 141

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

Answer:-

The code for the above program is given below, i have commented in line for the explanation.

Code:-

#include <iostream>

using namespace std;

void reverse(int arr[][4], int row, int col)
{
// array for storing new array
int arr2[row][col];
  
// for every row in arr1
for(int i=0;i<row;i++)
{
// for every column in a row arr1
for(int j=0;j<col;j++)
{
// this is where we reverse the array
arr2[row-1-i][col-1-j]=arr[i][j];
}
}
  
// print old array
cout<<"\nOld 2D array was: \n";
for(int i=0;i<5;i++)
{
for(int j=0;j<4;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
  
// porint new array
cout<<"\nNew 2D array is: \n";
for(int i=0;i<5;i++)
{
for(int j=0;j<4;j++)
{
cout<<arr2[i][j]<<" ";
}
cout<<endl;
}
}

int main()
{
// array to store user input in a array
int arr[5][4];
cout<<"Enter the 2D array elements : \n";
for(int i=0;i<5;i++)
{
for(int j=0;j<4;j++)
{
cin>>arr[i][j];
}
}
  
// function call to reverse the array
reverse(arr,5,4);
return 0;
}

Output:-

Enter the 2D array elements : 100 101 102 103 110 111 112 113 120 121 122 123 130 131 132 133 140 141 142 143 old 2D array wa

Hope it clears your doubt, do give a thums up if it helps you :)

Add a comment
Know the answer?
Add Answer to:
Write a program that (use C++) if u can use or <iostream> or <stdio.h> or both...
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
  • How do I plot a series graph with this data provided? Month 1987 1988 1989 1990...

    How do I plot a series graph with this data provided? Month 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 Jan 95 104 101 88 132 125 111 127 119 147 Feb 94 100 96 110 109 118 123 129 147 146 Mar 98 99 82 129 101 121 121 132 164 133 Apr 96 88 84 113 111 140 139 108 135 148 May 95 89 85 114 140 141 119 115 124 141 Jun 115 108...

  • Section II – Suppose we gathered the data below by an unbiased method. (The data is...

    Section II – Suppose we gathered the data below by an unbiased method. (The data is sorted DOWN the columns.) Use the data to create a histogram using six (6) classes. First class should start at 111. Give the Five-number summary of the data. Describe the data set. Be specific and note any gaps and/or outliers. Use the 1.5-IQR test to locate outliers. What description of center would be appropriate for the data set? Explain why? Draw a box plot....

  • Please do NOT use Minitab - show all calculations for creating the probability plot. Using Excel...

    Please do NOT use Minitab - show all calculations for creating the probability plot. Using Excel is okay. Reconsider Problem 3 in Homework 3. Is the set of measurements well described by a normal distribution? Show all the calculations. The measurements of a temperature sensor (in °F) are shown below. 124 118 131 125 133 123 120 119 128 133 127 125 131 124 129 121 142 151 160 125 121 136 140 137 125 124 128 129 130 141...

  • 4.15 construct a box plot for the data in exercise 4.1 down, then across Table 4B...

    4.15 construct a box plot for the data in exercise 4.1 down, then across Table 4B Electronic Component Failure Time 127 125 131 124 123 120 121 136 140 118 131 125 56 Chapter 4 Statistical Inference about Product Table 4E. Continued 119 128 133 137 124 142 123 137 125 124 128 129 130 122 133 124 129 121 142 151 160 125 141 125 140 131 129 126

  • (Use Excel) italy common for people to put on weight when they quit smoking While a...

    (Use Excel) italy common for people to put on weight when they quit smoking While a small weight gain is normal c e weight gain can create new health concerns that brode the benefits of not smoking. The accompanying table shows a portion of the weight data for 50 women before quitting and six months after quitting Use Table 2 Weight Before Quilling 140 144 138 Weight After Quilling 155 142 163 146 129 149 136 127 158 145 118...

  • a. Calculate the sample average. b. Calculate the sample standard deviation. 4. The time to failure...

    a. Calculate the sample average. b. Calculate the sample standard deviation. 4. The time to failure in hours of an electronic component subjected to an accelerated life test is shown in Table 3E.1. To accelerate the failure test, the units were tested at an elevated temperature (read down, then across). a. Calculate the sample average and standard deviation. b. Construct a histogram. c. Construct a stem-and-leaf plot. d. Find the sample median and the lower and upper quartiles. TABLE 3E.1...

  • Maintaining a healthy weight is important for women’s health. Some physicians recommend being back to your...

    Maintaining a healthy weight is important for women’s health. Some physicians recommend being back to your pre-pregnancy weight six months after giving birth. Public health officials are interested in whether this is a realistic goal. Do the women in North Carolina weigh more than their pre-pregnancy weight six months postpartum? In other words, is the six months post-pregnancy weight greater than their pre-pregnancy weight? Use a paired samples t-test to compare pst6wght (variable 1) and prewght (variable 2). This uses...

  • 1. The data are from the U.S. Department of Health and Human Services, National Center of...

    1. The data are from the U.S. Department of Health and Human Services, National Center of Health Statistics, Third National Health and Nutrition Examination Survey. The systolic blood pressure (mmHg) for 80 patients was measured. The following data is separated by gender Females: 89 92 93 93 94 95 97 98 99 100 101 102 104 104 104 105 106 106 107 107 107 108 108 110 112 113 113 114 114 116 116 118 119 123 124 125 127...

  • Grambling State University Department of Mathematies and Physics Probability and Statisties 1,SPLING 2019 Exam I, 01/23/2019...

    Grambling State University Department of Mathematies and Physics Probability and Statisties 1,SPLING 2019 Exam I, 01/23/2019 Please show all the details I. The amount of protein(in grams) for a variety of some fast food reported here. 1. Construct a frequency distribution using 6 cl a histogram, a frequency polygon, and an ogive for the data. 123, 130, 120, 127, 144, 126, 135, 120, 129, 129, 125, 115, 118, 127, 119, 122, 112, 126, 134, 115, 127, 135, 126, 143, 135,...

  • 24) Two groups of randomly selected drivers are surveyed to see how many miles per week...

    24) Two groups of randomly selected drivers are surveyed to see how many miles per week they drive for pleasure trips. At alpha equal to 0.01, can it be concluded that single drivers do more driving for pleasure trips on average than married drivers? Assume the population standard deviation for single drivers to be 16.7 and the population standard deviation for married drivers to be 16.1. Test the hypothesis using the methods listed below. Single drivers 110 97 Married drivers...

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