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

c++ code Reverse the order of elements in a vector of integers using two functions: (a)...
c++ code Reverse the order of elements in a vector of integers using two functions: (a) The first function takes the input vector a and return a vector b with the input data but in the reverse order, e.g. input: 1, 2, 3 and output 3, 2, 1. (b) The second function is a recursive one and it reverses the input data in place (without using an additional vector).
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++ .
The List method addAll(i,c) inserts all elements of the Collection c into the list at position...
The List method addAll(i,c) inserts all elements of the Collection c into the list at position i. (The add(i,x) method is a special case where c = {x}.) Explain why, for the data structures in this chapter, it is not efficient to implement addAll(i,c) by repeated calls to add(i,x). Design and implement a more efficient implementation.
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
Write method reverseStack(Stack s) that receives a stack s and reverse the order of its elements....
Write method reverseStack(Stack s) that receives a stack s and reverse the order of its elements. the values inside the stack must be changed, that the top will be the last and so on. please use java code to slove. Thank you.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT