// ============================================ // Week 3: Arrays (p. 11) int d1 = 10; int d2 = 3; cout << d1 / d2 << "\n"; double d3 = 10; int d4 = 3; cout << d3 / d4 << "\n"; int d5 = 10; double d6 = 3; cout << d5 / d6 << "\n"; // ============================================ // Week 3: Arrays (p. 16) int score[5]; for (int i = 0; i < 5; i++) cin >> score[i]; for (int i = 0; i < 5; i++) cout << score[i] << " "; cout << score; // ============================================ // Week 3: Arrays (p. 19) int array[100]; for (int i = 0; i < 100; i++) { cout << array[i] << " "; if (i % 10 == 9) cout << "\n"; } // ============================================ // Week 3: Arrays (p. 21) int array[100] = {0}; for (int i = 0; i < 500; i++) { cout << array[i] << " "; if (i % 10 == 9) cout << "\n"; } // ============================================ // Week 3: Arrays (pp. 26 and 28) float value[10] = {0}; for (int i = 0; i < 10; i++) cin >> value[i]; for (int i = 0; i < 9; i++) { if (value[i] > value [i + 1]) { float temp = value[i + 1]; value[i + 1] = value[i]; value[i] = temp; } } cout << value[9]; // ============================================ // Week 3: Arrays (p. 29) float value[10] = {0}; for (int i = 0; i < 10; i++) cin >> value[i]; float max = value[0]; for (int i = 1; i < 10; i++) { if (value[i] > max) max = value[i]; } cout << max; // ============================================ // Week 3: Arrays (p. 36) int a[2][3] = {{1, 2, 3}, {1, 2, 3}}; int b[2][3] = {{4, 5, 6}, {7, 8, 9}}; int c[2][3] = {0}; for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) c[i][j] = a[i][j] + b[i][j]; } // ============================================ // Week 3: Arrays (p. 38) int a[2][3]; cout << a << " " << a[0] << " " << a[1] << endl; // ============================================ // Week 3: Arrays (p. 39) int a[2][3]; cout << a << " " << a[0] << endl; cout << a[1] << " " << a + 1 << endl; cout << sizeof(a) << " " << sizeof(a[0]) << endl; // ============================================ // Week 3: Arrays (p. 45) int array[10]; cin >> array; return 0; char array[10]; cin >> array; return 0; // ============================================ // Week 3: Arrays (p. 46) char str[10]; cin >> str; // if we type "abcde" cout << str[0]; // 'a' cout << str[2]; // 'c¡¦ // ============================================ // Week 3: Arrays (p. 47) char array[10] = {'a', 'b', 'c'}; cout << array; // "abc" return 0; // ============================================ // Week 3: Arrays (p. 50) char a[100] = "abcde FGH"; cout << a << endl; // abcde FGH char b[100] = "abcde\0 FGH"; cout << b << endl; // abcde // ============================================ // Week 3: Arrays (p. 51) char c[100]; cin >> c; // "123456789" cin >> c; // "abcde"; cout << c << endl; // "abcde" c[5] = '*'; cout << c << endl; // "abcde*789" // ============================================ // Week 3: Arrays (p. 52) char a[5]; cin >> a; // "123456789" cout << a; // "123456789" or an error // ============================================ // Week 3: Arrays (p. 53) char a1[100]; cin >> a1; // "this is a string" cout << a1; // "this" char a2[100] = {'a', 'b', ' ', 'c', '\0', 'e'}; cout << a2; // ab c // ============================================ // Week 3: Arrays (p. 54) char a[100]; cin.getline(a, 100); // "this is a string" cout << a << endl; // "this is a string"