Cpp_notes_summary_4

Cpp_notes_summary_4 - Chapter 4 Arrays Skipped enumerated...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 4 Arrays Skipped enumerated type 4.1 Arrays #include < iostream > using namespace std ; int main () { int array1 [3]= { 3 ,2 ,1 } ; cout << array1[0] << ” , ” << array1[2] << endl ; int array2 [ 3 ] ; array2 [0]=1; array2 [1]=2; array2 [2]=3; int array3 [2][2]= {{ 1 ,2 } , { 3 ,4 }} ; cout << array3 [0][0] < < ” , ” << array3 [1][0] < < endl ; int array4 [ 3 ] [ 4 ] ; for ( int i =0; i < 3; i++) { for ( int j =0;j < 4; j++) { array4 [ i ] [ j ]= i j 1; } } return 0; } #include < iostream > using namespace std ; 13
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MAT 5939-04 Pierre Garreau void printarray ( int A[ ] , int N) { for ( int i =0; i < N 1; i++) { cout << ”A[ ” << i << ”]=” << A[ i] << ” , ” ; } cout << ”A[ ” << N 1 << ”]=” << A[N 1] << endl ; } int main () { int array1 [4]= { 1 ,2 ,3 ,4 } ; printarray ( array1 , 4 ) ; return 0; } Arrays are always passed as reference, so watch out you can change their value on purpose or by accident. Also notice that since the arrays start at zero these formulae look strange. If you are using arrays and your code doesn’t work the very Frst thing you should do is check your indexing. 9 times out of 10 you screwed it up at least once. #include < math . h > #include < iostream > using namespace std ; void cross product ( double A[ 3 ] , double B[ 3 ] , double cross [ 3 ] ) { cross [0]=(A[ 1 ] B[2] A[ 2 ] B[ 1 ] ) ; cross [1]= (A[ 2 ] B[0] A[ 0 ] B[ 2 ] ) ; cross [2]=(A[ 0 ] B[1] A[ 1 ] B[ 0 ] ) ; } int main () { double X[ 3 ] = { 1 . , 2 . , 3 .
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2012 for the course MAT 5939 taught by Professor Garreau during the Fall '11 term at FSU.

Page1 / 6

Cpp_notes_summary_4 - Chapter 4 Arrays Skipped enumerated...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online