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
Write code to reverse the order of elements on a stack S.c++ ii. Using one additional...
Write code to reverse the order of elements on a stack S.c++ ii. Using one additional queue. iii. using an additional stack and a non array variable c++ .
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
Write a method public static Stack reverse(Stack s) that reverses the order of elements on stack...
Write a method public static Stack reverse(Stack s) that reverses the order of elements on stack s using a Queue. Test your method using some example stacks. In java
C++ question. I want to write all output to the file "output.txt", but it will write...
C++ question. I want to write all output to the file "output.txt", but it will write just first character. Can you fix it? #include #include #include #include #include using namespace std; using std::cin; using std::cout; using std::string; // remove dashes convert letters to upper case string normalize(const string &isbn) { string ch; for (char i : isbn) { if (i == '-') { continue; // if "-" then skip it }    if (isalpha(i)) { i = toupper(i); // Check...
C++ question. I want to write all output to the file "output.txt", but it will write...
C++ question. I want to write all output to the file "output.txt", but it will write just first character. Can you fix it? #include #include #include #include #include using namespace std; using std::cin; using std::cout; using std::string; // remove dashes convert letters to upper case string normalize(const string &isbn) { string ch; for (char i : isbn) { if (i == '-') { continue; // if "-" then skip it }    if (isalpha(i)) { i = toupper(i); // Check...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT