• Jun 17, 2024 •oceantran27
0 likes • 3 views
#include <iostream> using namespace std; int main { cout << 1; }
• Sep 3, 2023 •AustinLeath
0 likes • 10 views
#include "stdio.h" #include <stdlib.h> int main (int argCount, char** args) { int a = atoi(args[1]); int b = atoi(args[2]); unsigned int sum = 0; unsigned int p = 1; for (unsigned int i = 1; i < b; i++) { p = p * i; } // (b!, (1 + b)!, (2 + b)!, ..., (n + b)!) for (unsigned int i = 0; i < a; i++) { p = p * (i + b); sum = sum + p; } printf("y: %u\n", sum); return 0; }
• 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; }
• 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; }
0 likes • 0 views
using namespace std; class Hash { int BUCKET; // No. of buckets // Pointer to an array containing buckets list<int> *table; public: Hash(int V); // Constructor // inserts a key into hash table void insertItem(int x); // deletes a key from hash table void deleteItem(int key); // hash function to map values to key int hashFunction(int x) { return (x % BUCKET); } void displayHash(); }; Hash::Hash(int b) { this->BUCKET = b; table = new list<int>[BUCKET]; } void Hash::insertItem(int key) { int index = hashFunction(key); table[index].push_back(key); } void Hash::deleteItem(int key) { // get the hash index of key int index = hashFunction(key); // find the key in (inex)th list list <int> :: iterator i; for (i = table[index].begin(); i != table[index].end(); i++) { if (*i == key) break; } // if key is found in hash table, remove it if (i != table[index].end()) table[index].erase(i); } // function to display hash table void Hash::displayHash() { for (int i = 0; i < BUCKET; i++) { cout << i; for (auto x : table[i]) cout << " --> " << x; cout << endl; } } // Driver program int main() { // array that contains keys to be mapped int a[] = {15, 11, 27, 8, 12}; int n = sizeof(a)/sizeof(a[0]); // insert the keys into the hash table Hash h(7); // 7 is count of buckets in // hash table for (int i = 0; i < n; i++) h.insertItem(a[i]); // delete 12 from hash table h.deleteItem(12); // display the Hash table h.displayHash(); return 0; }
• Oct 7, 2023 •AustinLeath
0 likes • 12 views
#include <iostream> #include <cstring> #include <unistd.h> #include <sys/utsname.h> int main() { char newHostname[] = "newhostname"; // Replace with the desired hostname if (sethostname(newHostname, strlen(newHostname)) == 0) { std::cout << "Hostname set to: " << newHostname << std::endl; // Optionally, update the /etc/hostname file to make the change permanent FILE *hostnameFile = fopen("/etc/hostname", "w"); if (hostnameFile != NULL) { fprintf(hostnameFile, "%s\n", newHostname); fclose(hostnameFile); } else { perror("Failed to update /etc/hostname"); } } else { perror("Failed to set hostname"); } return 0; }