how to Transfer/Array ???
@Callisto help me mamen ... :D
int arr[rows][columns] = {{entries in first row}, {entries in second row}, ... {entries in the last row}};
for all 0's entries, if I remember correctly, you just need {0} for the initialization.
Maybe you should try the transfer part first.
yeah its always start at 0
yeah i need to transfer it..
but the questin is how??
Have you tried?
im now trying to answer...
When you do the transfer, you probably need a temp array.
i just need a guide to answer it...
Ok, tell me what you have got.
thats for the transfer
for (a=0; a<5; a++) { cin>>Array[a]; } for (b=0;b<4;b++) { for (int c=0;c<4-b;b++) { if (Array[c]>Array[c+1]) { temp=Array[c]; Array[c]=Array[c+1]; Array[c+1]=temp; } } }
Post the whole programme here: http://pastebin.com/ Post the link here again after you post the code here
ok
I really need to read the WHOLE programme, or else, add comments in your code. I don't even know which array is storing what values.
ok... wait
Sorry, you need not use a temp array...
ok .. what should i do??
Your code looks so complicated as well. Here's what I've got. http://pastebin.com/nzGe8sTW
thank you Callisto ^_^
hahah
When you print an 2D array, you need a nested for-loop (for loop inside a for-loop)
uhh
I don't see why you need a if-else statement there as well.
hehehh sorry
It's ok.. By the way, I just realized that I did something silly in my code. You may want to improve that code I posted. Big thanks to @experimentX for spotting it out :)
hehehe thank you @experimentX ^_^
yw ... both of you. it's better to write a module to print the content of arrays ... since you need to repeat it 4 times.
uhhh
@Callisto i have some question ...... :D
can you help me @Callisto ??
?
what statement should i change in the Transfer if i change the 10 1 9 2 8 3 7 4 6 5 to 1 2 3 4 5 6 7 8 9 10
Your guess?
like this
i observe that it counts from left to right and it is increasing
And what have you got for this question so far?
what statement should i put in the program to display 1 2 3 4 5 6 7 8 9 10
Just to display this?
Use a nested for loop to do it.
or the statement to change the //transfer
to display that
Show me your program.
remember??
but that already correct but we need to change the //transfer to get the 1 2 3 4 5 6 7 8 9 10
//transfer for(int i=0; i<5; i++){ arr2[i][0] = arr1[1][i]; } for(int i=0; i<5; i++){ arr2[i][1] = arr1[0][i]; }
we need to make new one in that part..
So what have you tried?
yeah i tried but so far
Show me what you have got then.
int a; //transfer for(int i=0; i<5; i++){ if arr2[a][0]= arr1[1][i]; a++
i dont know... hehehe
wait
the table is like this right?? 00 01 10 11 20 21 30 31 40 41
int a; //transfer for(int row=0; row<2; row++){ for(int col=0; col<5; col++){ if arr2[row][0]= arr1[1][col];
@Callisto
What are you doing in this piece of code? //transfer for(int row=0; row<2; row++){ for(int col=0; col<5; col++){ if arr2[row][0]= arr1[1][col];
sorry
Find a paper, write the the output with that piece of code, you'll know what you were doing.
#include<iostream> using namespace std; int main() { int arr1[2][5]={{1,2,3,4,5}, {10,9,8,7,6}}; int arr2[5][2]={0}; int i; //print the first array for(int i=0; i<2; i++){ for(int j=0; j<5; j++){ cout << arr1[i][j] << " "; } cout << endl; } cout << endl; //print the second array for(int i=0; i<5; i++){ for(int j=0; j<2; j++){ cout << arr2[i][j] << " "; } cout << endl; } cout << "\nAfter transfer... \n" << endl; //transfer the entry in array 1 to array 2. for(int row=0; row<5; row++){ for( col==0) if arr2[row][col]= arr1[row][i]; } i++ } return 0;
Have you compiled the programme?
for(int row=0; row<5; row++){ for( col==0) if arr2[row][col]= arr1[row][i]; <--- what is this line doing? i++ }
#include<iostream> using namespace std; int main() { int arr1[2][5]={{1,2,3,4,5}, {10,9,8,7,6}}; int arr2[5][2]={0}; int a; //print the first array for(int i=0; i<2; i++){ for(int j=0; j<5; j++){ cout << arr1[i][j] << " "; } cout << endl; } cout << endl; //print the second array for(int i=0; i<5; i++){ for(int j=0; j<2; j++){ cout << arr2[i][j] << " "; } cout << endl; } cout << "\nAfter transfer... \n" << endl; //transfer the entry in array 1 to array 2. for(int row=0; row<5; row++){ for( col==0) if arr2[row][col]= arr2[row][a]; else arr1[1][a]=arr1[0][a]; a++ }
if-else is a conditional statement... if (something) do something here if it is true else do something here if it is false
Example: int x = 1; if (x == 1) cout << "cheers" << endl; // print "cheers" if x = 1 else cout << "NO" << endl; // print "NO" if x is not equal to 1
uhh
//transfer the entry in array 1 to array 2. for(int row=0; row<5; row++){ for( col==0) if arr2[row][col]= arr2[row][a]; if arr1[1][a]=arr1[0][a]; a++ } can i make it like this??
Of course you can't.
aww
hhehehe
Have you revised before you do the programming exercises? My advice is that you'd better revise before you carry on.
no
??
#include<iostream> #include<iomanip> using namespace std; void main(){ int arr1[2][5]={{1,2,3,4,5},{10,9,8,7,6}}; int arr2[5][2]={0}; int x, y; cout<<"Array 1"<<endl; for(x=0;x<2;x++){ for(y=0;y<5;y++){ cout<<setw(2)<<arr1[x][y];} cout<<endl;} cout<<endl<<"Array 2:"<<endl; for(x=0;x<5;x++){ for(y=0;y<2;y++){ cout<<setw(2)<<arr2[x][y]<<" ";} cout<<endl;} for(x=0;x<2;x++){ for(y=0;y<5;y++){ if(x==1){ arr2[y][0]=arr1[x][y];} else if(x==0){ arr2[y][1]=arr1[x][y];} } cout<<endl<<"After Array Manipulation:"<<endl; cout<<endl<<"Array 1"<<endl; for(x=0;x<2;x++){ for(y=0;y<5;y++){ cout<<setw(2)<<arr1[x][y]<<" ";} cout<<endl;} cout<<endl<<"Array 2:"<<endl; for(x=0;x<5;x++){ for(y=0;y<2;y++){ cout<<setw(2)<<arr2[x][y]<<" ";} cout<<endl;} }
revise??
Revise = study.
What are you trying to do in the new code?
yeah i need a new code on the part of Transfer..
Ok, you edit my code and here is what you got after your edition to my code: Array 1 1 2 3 4 5 10 9 8 7 6 Array 2: 0 0 0 0 0 0 0 0 0 0 After Array Manipulation: Array 1 1 2 3 4 5 10 9 8 7 6 Array 2: 0 1 0 2 0 3 0 4 0 5
aww still i dont got the right answer :/
Do you know what the function setw(int n) does?
int n is infinite?? its also it defend to user until when to end
joke.. i dont know
But you added that function to your code.
If you don't try to write it yourself, you can never write it.
okok
Join our real-time social learning platform and learn together with your friends!