Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C, can you also show the output too pls! // Enter your name here // State the IDE that you use: Visual Studio or

in C, can you also show the output too pls!

// Enter your name here // State the IDE that you use: Visual Studio or GCC // Your code will be compiled and ran using GCC. Keep this in mind. #include #include #pragma warning(disable : 4996) // compiler directive for Visual Studio only // Read before you start: // You are given a partially complete program. Your job is to complete the functions in order for this program to work successfully. // All instructions are given above the required functions, please read them and follow them carefully. // You shoud not modify the function return types or parameters. // You can assume that all inputs are valid. Ex: If prompted for an integer, the user will input an integer. // Global Macro Values. They are used to define the size of 2D array of integers #define NUM_ROWS 5 #define NUM_COLUMNS 5 #define NUM_STRINGS 5 #define STRING_LENGTH 50 // Forward Declarations void printMatrix(int[NUM_ROWS][NUM_COLUMNS]); void createMatrix(); void scalarMatrix(int[NUM_ROWS][NUM_COLUMNS], int); void sumRowsDiv(int[NUM_ROWS][NUM_COLUMNS]); void transposeMatrix(int[NUM_ROWS][NUM_COLUMNS]); void reverseStrings(char strings[NUM_STRINGS * STRING_LENGTH]); void removeChar(char strings[NUM_STRINGS * STRING_LENGTH], char); void splitAndPrintWords(char s[NUM_STRINGS*STRING_LENGTH]); // Problem 1: printMatrix (5 points) // Traverse the 2D array of the integers 'matrix' (input from main) // and print the contents in the following format (actual contents may vary) // e.g. // 1 2 3 4 5 // 6 7 8 9 10 // 11 12 13 14 15 // 16 17 18 19 20 // 21 22 23 24 25 void printMatrix(int matrix[NUM_ROWS][NUM_COLUMNS]) { // Enter code below } // Problem 2: createMatrix (5 points) // Create and return a 2D array of integers using a for loop // to generate and print the following matrix: // 0 1 2 3 4 // 1 2 3 4 5 // 2 3 4 5 6 // 3 4 5 6 7 // 4 5 6 7 8 // Hint: Use printMatrix to print the result

void createMatrix(){ // Enter code below } // Problem 3: scalarMatrix (5 points) // Traverse the 2D array of integers 'matrix' and multiply each element of the matrix by a scalar value // print the resulting matrix // Hint: Use printMatrix to print the result // e.g. // 1 2 3 2 4 6 // 4 5 6 => 8 10 12 // 7 8 9 14 16 18 // void scalarMatrix(int matrix[NUM_ROWS][NUM_COLUMNS], int multiple) { // Enter code below } // Problem 4: sumRowsDiv (5 points) // Traverse the 2D array of the integers 'matrix' and print the sum of each row divided by 5 on its own line. // e.g. // 1 2 3 4 5 // 6 7 8 9 10 // 11 12 13 14 15 => 3 8 13 18 23 // 16 17 18 19 20 // 21 22 23 24 25 void sumRowsDiv(int matrix[NUM_ROWS][NUM_COLUMNS]) { // Enter code below } // Problem 5: transposeMatrix (5 points) // Take the 2D array of integers 'matrix' and print the tranpose matrix. // You may assume that row and column counts are equal. // Hint: Use printMatrix to print the result // e.g. // 1 2 3 4 5 1 6 11 16 21 // 6 7 8 9 10 2 7 12 17 22 // 11 12 13 14 15 => 3 8 13 18 23 // 16 17 18 19 20 4 9 14 19 24 // 21 22 23 24 25 5 10 15 20 25 void transposeMatrix(int matrix[NUM_ROWS][NUM_COLUMNS]) { // Use this matrix to store each element int matrix2[NUM_ROWS][NUM_COLUMNS]; // Enter code below } // Problem 6: reverseString (5 points) // Reverse each string of strings[]. // Consider one string at a time and reverse the characters. For instance, "hi hello" should reverse to "olleh ih". // begin with swapping first and last letter. // We have 2 indices: i begins from start and increments, len begins from end and decrements

// run the swapping logic length/2 times // return the string at the end. void reverseStrings(char strings[NUM_STRINGS * STRING_LENGTH]) { // Enter code below } // Problem 7: removeChar (5 points) // "Remove" all occurrences of the specified character 'remove' from s[]. // To accomplish this, you will copy the contents of s into the provided removed[] array while ignoring // the specified character. Print the resulting array. // Hint: You will want to keep track of the size of removed[] for printing. void removeChar(char s[NUM_STRINGS * STRING_LENGTH], char remove) { // Use this array and integer to store the new string char removed[NUM_STRINGS*STRING_LENGTH]; int removed_size = 0; // Enter code below } // Problem 8: splitAndPrintWords (5 points) // Split s[] into individual words and store them in str[][]. // Read s[] character by character and copy into str[][], such that word 1 is in str[0][], // word 2 is in str[1][], and so on. Print the char array str[][], so that the separated words are // printed on their own line. Finally return the number of words using the variable 'count'. // Don't forget to initialize str[][] with the null terminator character '\0'. // Hint: Words are separated by whitespace characters // e.g. // "The quick brown fox jumped over the lazy dog" // The // quick // brown // fox // jumped // over // the // lazy // dog // // *** IMPORTANT NOTE: Test Problems 7 under GCC. VS has been known to cause some minor character trimming issues, // if you experience these, try with GCC. *** void splitAndPrintWords(char s[NUM_STRINGS*STRING_LENGTH]){ char str[NUM_STRINGS][STRING_LENGTH]; // Enter code below } // You should study and understand how this main() works. // *** DO NOT modify it in any way *** // *** Modifying this code will disrupt the autograder *** int main() { printf("CSE240 HW3: 2D Integer Arrays ");

int matrix[NUM_ROWS][NUM_COLUMNS] = { {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}, {21, 22, 23, 24, 25} }; printMatrix(matrix); printf(" "); createMatrix(); printf(" "); scalarMatrix(matrix, 4); printf(" "); sumRowsDiv(matrix); printf(" "); transposeMatrix(matrix); printf(" "); printf(" CSE240 HW3: 2D Character Arrays "); char words[NUM_STRINGS * STRING_LENGTH]; printf(" Enter sentence with max 5 words: "); fgets(words, sizeof(words), stdin); reverseStrings(words); printf(" Reversed string: %s ", words); printf("String with \'b\' removed:"); removeChar(words, 'b'); printf(" Split String: "); splitAndPrintWords(words); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How would you respond to each of the girls?

Answered: 1 week ago