• Nov 18, 2022 •AustinLeath
0 likes • 4 views
#include <iostream> using namespace std; int main() { const int ROW_SIZE = 2; const int COLUMN_SIZE = 5; //establish all variables int matrix[ROW_SIZE][COLUMN_SIZE]; int minVal; for (int i = 0; i < ROW_SIZE; ++i) // for loop to ask user to enter data. { for (int h = 0; h < COLUMN_SIZE; ++h) { cout << "Enter data for row #" << i + 1 << " and column #" << h + 1 << ": "; cin >> matrix[i][h]; } } cout << "You entered: " << endl; for (int i = 0; i < ROW_SIZE; ++i) //for statements to output the array neatly { for (int h = 0; h < COLUMN_SIZE; ++h) { cout << matrix[i][h] << "\t"; } cout << endl; } cout << "Minimum for each row is: {"; for (int i = 0; i < ROW_SIZE; i++) //for statements to find the minimum in each row { minVal = matrix[i][0]; for (int h = 0; h < COLUMN_SIZE; h++) { if (matrix[i][h] < minVal) // if matrix[i][h] < minVal -> minVal = matrix[i][h]; { minVal = matrix[i][h]; } } cout << minVal << ", "; } cout << "}" << endl; cout << "Minimum for each column is: {"; for (int i = 0; i < COLUMN_SIZE; i++) //for statements to find the minimum in each column { minVal = matrix[0][i]; for (int h = 0; h < ROW_SIZE; h++) { if (matrix[h][i] < minVal) //replaces minVal with array index for that column that is lowest { minVal = matrix[h][i]; } } cout << minVal << ", "; } cout << "}" << endl; return 0; }
• Jun 17, 2024 •oceantran27
0 likes • 3 views
#include <iostream> using namespace std; int main { cout << 1; }
• Aug 31, 2020 •joshwrou
1 like • 2 views
#include <iostream> using namespace std; int main() { cout << "Hello World!\n"; // Prints out "Hello World" return 0; }
• Aug 25, 2023 •LeifMessinger
1 like • 12 views
#include <iostream> int main(){ const char* const hello = "Hello, world!"; const char* bruh = hello; char* const yeet = hello; std::cout << bruh << std::endl; std::cout << yeet << std::endl; return 0; } /* Place your bets! Will the program: a.) Print "Hello, world!" twice? b.) Compile error on line 5 (bruh initialize line) because the pointer gets implicit cast to non-const? c.) Compile error on line 7 (yeet initialize line) because the char gets implicit cast to non-const? d.) Both b and c? e.) Compile error line 11 (print yeet) because the pointer is constant and can't be incremented f.) Print "Hello, world!" then print the pointer address in hexadecimal g.) Both b and e? h.) Both c and e? i.) B, c, and e? */ // The answer is in this base 64 string: // T25seSBjLikKVGhlIGNvbXBpbGVyIGRvZXNuJ3QgYXBwcmVjaWF0ZSB5b3UgbWFraW5nIHRoZSBjaGFyYWN0ZXJzIHRoZSBwb2ludGVyIHJlZmVycyB0byBub24tY29uc3QsIGJ1dCBpdCdzIGZpbmUgd2l0aCB5b3UgY29weWluZyBhIGNvbnN0YW50IHZhbHVlLCBpLmUuIHRoZSBwb2ludGVyLCB0byBhIG5vbi1jb25zdGFudCB2YXJpYWJsZS4KSWYgeW91IHJlcGxhY2UgdGhhdCBsaW5lIHdpdGggY2hhciogY29uc3QgeWVldCA9IGNvbnN0X2Nhc3Q8Y2hhciogY29uc3Q+KGhlbGxvKTsgSXQnbGwgcHJpbnQgIkhlbGxvLCB3b3JsZCEiIHR3aWNlLCB3aGljaCBpcyB2ZXJ5IHN0cmFuZ2UgY29uc2lkZXJpbmcgdGhhdCB5ZWV0IGlzIGEgY29uc3QgcG9pbnRlciwgc28geW91J2QgdGhpbmsgaXQgd291bGQgcHJpbnQgYXMgYSBoZXhhZGVjaW1hbCBiZWNhdXNlIGlmIHlvdSB0cnkgdG8gKCsreWVldCkgd2hpbGUgbG9vcGluZyB0aHJvdWdoIHRoZSBzdHJpbmcsIHlvdSdkIGdldCBhbiBlcnJvciwgYmVjYXVzZSBpdCdzIGNvbnN0IGFuZCBjYW4ndCBiZSBjaGFuZ2VkLgpJbnN0ZWFkIG9mIHVzaW5nIGEgdGVtcGxhdGUgZnVuY3Rpb24gZm9yIG9zdHJlYW06Om9wZXJhdG9yPDwsIHRoZXkgbWFrZSBpdCBhIGZ1bmN0aW9uIHRoYXQgdGFrZXMgdHlwZSBjb25zdCBjaGFyKiwgYW5kIEMrKyBoYXMgbm8gcHJvYmxlbXMgcHJvbW90aW5nIGEgdmFyaWFibGUgdG8gY29uc3RhbnQgd2hlbiBpbXBsaWNpdCBjYXN0aW5nLCBhbmQgaXQgaGFzIG5vIHByb2JsZW1zIGltcGxpY2l0IGNhc3RpbmcgdGhlIGNvbnN0IHBvaW50ZXIgdG8gYSBub3JtYWwgcG9pbnRlciBiZWNhdXNlIGl0J3MgbWFraW5nIGEgY29weS4gVGhlIHBvaW50ZXIgZ2V0cyBjb3BpZWQgYmVjYXVzZSB0aGUgcG9pbnRlciBpcyBwYXNzZWQgYnkgdmFsdWUsIG5vdCByZWZlcmVuY2Uu
0 likes • 15 views
#include<iostream> using namespace std; const int rows = 8; const int cols = 8; char chessboard[rows][cols]; void setBoard(char chessboard[][cols]); void printBoard(char chessboard[][cols]); void setBoard(char chessboard[][cols]) { for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) { if(i % 2 == 0 && j % 2 == 0) { chessboard[i][j] = 'x'; } else { if(i % 2 != 0 && j % 2 == 1) { chessboard[i][j] = 'x'; } else { chessboard[i][j] = '-'; } } } } return; } void printBoard(char chessboard[][cols]) { for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) { cout << chessboard[i][j] << " "; } cout << endl; } return; } int main(int argc, char const *argv[]) { setBoard(chessboard); printBoard(chessboard); return 0; }
• Aug 5, 2023 •usama
1 like • 5 views
/* Good morning! Here's your coding interview problem for today. This problem was asked by Stripe. Given an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well. For example, the input [3, 4, -1, 1] should give 2. The input [1, 2, 0] should give 3. You can modify the input array in-place. */ #include <iostream> using namespace std; int calcMissing(int* input, int size) { int sum = 0; int n = 1; //add one to account for missing value for(int i = 0; i < size; i++) { if(input[i] > 0) { sum += input[i]; n++; } } //If no numbers higher than 0, answer is 1 if(sum == 0) return 1; return (n*(n+1)/2) - sum; //Formula is expectedSum - actualSum /* expectedSum = n*(n+1)/2, the formula for sum(1, n) */ } int main() { cout << calcMissing(new int[4]{3, 4, -1, 1}, 4) << endl; cout << calcMissing(new int[3]{1, 2, 0}, 3) << endl; //No positive numbers cout << calcMissing(new int[1]{0}, 1) << endl; }