Question

In: Computer Science

I want to copy all the elements in f1() to f2() but in reverse order (C++)...

I want to copy all the elements in f1() to f2() but in reverse order (C++)

this is my code:

#include <iostream>
#include <iomanip>
using namespace std;

const int R=10;
const int C=10;
int Array[R][C] ;


/////////////////////////////////////
void f1(){

for(int i=0 ; i<R ; i++){
   for(int j=0 ; j<C ; j++){
Array[i][j]= (rand () %100) + 1;
}
}

for(int i=0 ; i<R ; i++){
   for(int j=0 ; j<C ; j++){
   cout<<"["<<i<<"]["<<j<<"]="<<setw(3)<<Array[i][j]<<" ";
   }
cout<<endl;
}

cout<<"\n\n\n";
}


void f2(){
cout<<"////////////////////////////////////"<<endl;
cout<<"\n";
const int R2=10;
const int C2=10;
int Array[R][C];

for (int i=0 ; R<R2 ;i++){
   for ( int j=0 ; C<C2 ; j++){
int swaping = Array[R][C];
Array[R][C]=Array [R2][C2];
Array [R2][C2]=swaping;
Array[R][C]++;
Array [R2][C2]--;

   cout<<"["<<i<<"]["<<j<<"]="<<setw(3)<<Array[i][j]<<" ";
}
}

cout<<"\n\n";


}


int main()
{
f1();
f2();


return 0;
}

Solutions

Expert Solution

Program

#include <iostream>
#include <iomanip>
using namespace std;

const int R=10;
const int C=10;
int Array[R][C] ;

void f1(){

for(int i=0 ; i<R ; i++){
for(int j=0 ; j<C ; j++){
Array[i][j]= (rand () %100) + 1;
}
}

for(int i=0 ; i<R ; i++){
for(int j=0 ; j<C ; j++){
cout<<"["<<i<<"]["<<j<<"]="<<setw(3)<<Array[i][j]<<" ";
}
cout<<endl;
}

cout<<"\n\n\n";
}


void f2(){
cout<<"////////////////////////////////////"<<endl;
cout<<"\n";
const int R2=10;
const int C2=10;
int Arraycopy[R][C];
int k=R2-1; //last index
int m=C2-1; //last index


for (int i=0 ; i<R2 ;i++){
m=C2-1;
for ( int j=0 ; j<C2 ; j++){
Arraycopy[i][j]=Array[k][m];
cout<<"["<<i<<"]["<<j<<"]="<<setw(3)<<Arraycopy[i][j]<<" ";
m--;
}
k--;
cout<<endl;
}

cout<<"\n\n";


}


int main()
{
f1();
f2();


return 0;
}

Screenshot of the program

Output

If you find this answer useful, please rate positive , thankyou


Related Solutions

I need the results of the F1 and F2 generation using Punnet Square for: 1. Monohybrid...
I need the results of the F1 and F2 generation using Punnet Square for: 1. Monohybrid cross between Parent gen. phenotypes scarlet and sepia drosophila 2. Dihybrid cross between Parent gen. phentotypes scarlet and yellow drosophila with ratios.
The following code was meant to print out the elements in an array in reverse order....
The following code was meant to print out the elements in an array in reverse order. However, it does not behave correctly. public static void reverse(int[] a, int index) {       if (index == (a.length - 1))         System.out.printf("%d%n", a[index]);       else {         reverse(a, index); What does it do? Explain why it behaves in this way and There is more than one error in the code. Correct the code so that it will recursively print out the elements of...
Compute each of the following: a. F1+F2+F3+F4+F5 b. F1+2+3+4 c. F3xF4 d. F3X4 Given that FN...
Compute each of the following: a. F1+F2+F3+F4+F5 b. F1+2+3+4 c. F3xF4 d. F3X4 Given that FN represents the Nth Fibonacci number, and that F31 =1,346, 269 and F33 = 3,524,578, find the following: a. F32 b. F34 25. Solve the quadratic equation using the quadratic formula: 3x^2-2x-11=0
I need a MIPS Assembly program that "Display the elements of the linked list in reverse...
I need a MIPS Assembly program that "Display the elements of the linked list in reverse order." It needs subprogram and those subprogram does not have t registers.
Let f1 = 1 and f2=1 and for all n>2 Let fn = fn-1+fn-2. Prove that...
Let f1 = 1 and f2=1 and for all n>2 Let fn = fn-1+fn-2. Prove that for all n, there is no prime p that divides noth fn and fn+1
The following code was meant to print out the elements in an array in reverse order. However, it does not behave correctly.
  The following code was meant to print out the elements in an array in reverse order. However, it does not behave correctly. public static void reverse(int[] a, int index) {       if (index == (a.length - 1))         System.out.printf("%d%n", a[index]);       else {          reverse(a, index); What does it do? Explain why it behaves in this way.                                    There is more than one error in the code. Correct the code so that it will recursively print out...
Urgent! pls show all ways of how to make a deep copy of each elements in...
Urgent! pls show all ways of how to make a deep copy of each elements in a singly linked list (linear time) (pls write code with explanation in java! Thanks in advance! )
C++. How do I reverse this encryption? Here is the question: "A company that wants to...
C++. How do I reverse this encryption? Here is the question: "A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your program should read a four-digit integer in main() entered by the user and encrypt it as follows: 1. Replace each digit with the result of adding 7 to the digit and...
Using C programming I have a file that contains earthquake data that I will copy and...
Using C programming I have a file that contains earthquake data that I will copy and paste below. I want to use either bubble or insertion sort to sort the file by latitude in ascending order, then create a new file containing the sorted data. example file to sort: time,latitude,longitude,depth,mag,magType,nst,gap,dmin,rms,net 2020-10-17T17:22:03.840Z,32.877,-116.2991667,0.31,1.16,ml,21,119,0.07747,0.26,ci 2020-10-17T17:17:29.980Z,34.1611667,-116.452,2.75,0.87,ml,17,66,0.05224,0.22,ci 2020-10-17T17:03:54.460Z,33.5396667,-116.4613333,8.66,0.63,ml,18,126,0.06084,0.16,ci 2020-10-17T16:55:01.080Z,63.254,-151.5232,8,1.4,ml,,,,0.9,ak
Write C program that reorders elements of an array of integers such that the new order...
Write C program that reorders elements of an array of integers such that the new order is in descending order (first number being the largest). Must have a main function and a swap function. - int main() will declare an array with the values { 32, 110, 79, 18, 22, 2}. This array will be passed to the swap function. - the void swap function will perform the necessary operations to reorder the elements of the array. - After swap()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT