Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are functions that are defined and used in the file. You are supposed to write the body of these functions. You must initialize the

There are functions that are defined and used in the file. You are supposed to write the body of these functions. You must initialize the arrays, pointers or any other variables that you declare before using them. PROGRAM: #include  #include #include  #define MAX_DIM 3 int matrixA[MAX_DIM][MAX_DIM], matrixB[MAX_DIM][MAX_DIM], sum[MAX_DIM][MAX_DIM]; /* Question 1: (5 points) Implement this function which is used to initialize matrix A and matrix B. This function should make both the 3x3 matrices as : 2 3 1 2 4 6 1 5 7 */ void initializeMatrix() { } /* Question 2: (10 points) Implement the function to add matrix A and matrix B. Store the result in matrix sum, which is already declared as a global variable. */ void addMatrix() { } /* Question 3: (10 points) Implement the function to display the 'sum' matrix. For instance, display : The matrix sum= 1 23 34 12 78 21 39 3 33 */ void displaySumMatrix() { } /* Question 4: (10 points) Implement the function to find the minimum element of the array 'a'. */ void minElement() { int min = 0; int a[10] = { 34,56,23,78,36,98,49,29,88,62 }; // Enter your code here printf("minimum element in arrayA[]: %d ",min); } /* Question 5: (10 points) Implement the function to take in 5 numbers from the user and calculate their average. You have to use pointer 'ptr' to store the five numbers. You may not add more variables. You may add variable 'int i' for 'for' loop if needed. */ void avgOfArray() { float avg = 0, *ptr = 0; printf("Enter 5 numbers: "); // Enter your code here printf("Average = %0.2f ", avg); } /* Question 6: (10 points) Implement the function that creates and displays the user name of the user. Ask the user for their first and last name. The username is the first letter of first name, followed by the last name. For instance, if the user's name is Kyle Mills, then the username is kmills. */ void createUsername() { char firstName[15], lastName[15], userName[20]; while(getchar() != ' '); // needed to get rid of left behind by scanf and similar functions in code above // Enter your code here printf("Your user name : %s", userName); } /* Question 7: (10 points) Count the number of upper case characters in array 'sentence' and convert upper case characters to lower case. Display the number of upper case characters and newly formed sentence[] which has all lower case characters. You may not add more variables than already declared. You may use 'int i' for 'for' loop, if needed. */ void upperToLowerCase() { char sentence[]="soMe uppEr CasE AnD loWeR cAse CharactERs"; int upperCases = 0; // Enter your code here printf("Number of upper case characters= %d ",upperCases); printf("New sentence is: %s ",sentence); } /* Question 8: (5 points) A constant integer 'c' is declared as 5. There is one way to change that value to some other value, say 12. Change the value of 'c' to 12. This is to demonstrate that the value of const can be changed in a way, and to be careful to not do it in a real working application. */ void changeConst() { const int c= 5; // Enter your code here printf("new value of c is %d ",c); } /* Question 9: (30 points) Implement the function to take in a 10-character string 'string'1' and 3-character pattern string 'pattern' from the user. Search for the 'pattern' in 'string1' and display "pattern found" if 'pattern' is found in 'string1'. For instance, if user enters string1= "abcdefghij" and pattern = "ghi", then the pattern exists in string1, so display "pattern found". Do not display anyhting if pattern is not found in string1. You MUST use pointers and not arrays for this question. You may use string functions. You may not add more variables than already declared. You may use 'int i' for 'for' loop, if needed. Note : When using fgets(), when you press Enter to finish entering the string, the Enter ( ) character is also added to the string. So a 10-character string actually looks like "abcdefghij \0". So consider storing 12 elements for 10-character string. */ void searchPattern() { char *string1, *pattern; int string1Len=0, patternLen=0; //while(getchar() != ' '); // use this line to get rid of left behind by scanf and similar functions in code above // Enter your code here } int main() { printf("Problem 1,2,3: "); initializeMatrix(); addMatrix(); displaySumMatrix(); printf("Problem 4: "); minElement(); printf("Problem 5: "); avgOfArray(); printf("Problem 6: "); createUsername(); printf("Problem 7: "); upperToLowerCase(); printf("Problem 8: "); changeConst(); printf("Problem 9: "); searchPattern(); 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

Recommended Textbook for

Entity Alignment Concepts Recent Advances And Novel Approaches

Authors: Xiang Zhao ,Weixin Zeng ,Jiuyang Tang

1st Edition

9819942527, 978-9819942527

More Books

Students also viewed these Databases questions