How to declarean array? Data type array name [size]; int array[4]; Initialize array int array [3] = {3, 4,5}; int array[3] ; array[0] = 3; array[1] = 4; array[2] =5; Accessing array For loop
Practice what is thevalue of sum after this code executes? 1. int[][] matrix = {{1,1,2,2},{1,2,2,4},{1,2,3,4},{1,4,1,2}}; 2. int sum = 0; 3. int col = matrix[0].length - 2; 4. for (int row = 0; row < 4; row++) { 5. sum = sum + matrix[row][col]; 6. }
C++ Function Declaration returnTypefunctionName (parameter1, parameter2,...) { // function body } // function declaration void greet() { cout << "Hello World"; }
16.
Example 1. #include <iostream> 2.using namespace std; 3. int addition (int a, int b) { 4. int r; 5. r=a+b; 6. return r; 7. } 8. int main () { 9. int z; 10. z = addition (5,3); 11. cout << "The result is " << z; 12. }
17.
Practices • Write aprogram that calculates 6^5. Declare your own function to do this.
18.
Practices Write a programwith function to find 3 largest number of an array. Array size: 8 Input: {7, 12, 9, 15, 19, 32, 56, 70}