Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Question
Chapter 7, Problem 14E
7.10
Program Plan Intro
Modified version of the exercise 7.10 with the global variables:
Program Plan:
- Include required header files.
- Give the function prototype.
- Declare the variable “n” and “val” as global variable
- Define the main function,
- Get the number from the user.
- Call the function “prime()”.
- Check whether “val” equals to “1”.
- Print the corresponding statement.
- Otherwise, if the condition fails,
- Print the corresponding statement.
- Definition for the function “prime()”,
- Declare the variable “i”.
- Use for loop to check the condition.
- Check whether the remainder equals to 0.
- Return the value “0”.
- Return the value “1”.
- Check whether the remainder equals to 0.
- Use for loop to check the condition.
- Declare the variable “i”.
a)
Program Plan Intro
Modified version of the exercise 7.12(a) with the global variables:
Program Plan:
- Include required header files
- Declare and initialize the array values globally
- Declare the array “Arr_2” globally.
- Definition for the function “isTrans(int A[4][5], int B[5][4])”
- Declare the variable “k” and “l”.
- For loop to check whether “k” is less than “4”
- For loop to check whether “j” is less than “5”
- Condition to check if both the elements in the array are not equal.
- Return the value “0”.
- Return the value “1”.
- Condition to check if both the elements in the array are not equal.
- Definition for the function “transposeMatrix(int A[4][5], int B[5][4])”
- Declare the variable “k” and “l”.
- For loop to check whether “k” is less than “4”
- For loop to check whether “j” is less than “5”
- Condition to check if both the elements in the array are equal.
- Return the value “0”.
- Condition to check if both the elements in the array are equal.
- Check whether “isTrans(A,B)” equals to 1.
- For loop to check whether “k” is less than “5”
- For loop to check whether “l” is less than “4”
- Print the element.
- Print new line.
- For loop to check whether “l” is less than “4”
- Otherwise, print the corresponding statement inside “else” clause.
- For loop to check whether “k” is less than “5”
- Define the main function
- Call the function “transpose()” by passing the array.
- Return the value “0”.
b)
Program Plan Intro
Modified version of the exercise 7.12(b) with the global variables:
Program Plan:
- Include required header files
- Definition for the function “isTrans(int A[row][col], int B[row][col])”
- Declare the variable “k” and “l”.
- For loop to check whether “k” is less than “row”
- For loop to check whether “j” is less than “col”
- Condition to check if both the elements in the array are not equal.
- Return the value “0”.
- Return the value “1”.
- Condition to check if both the elements in the array are not equal.
- Definition for the function “t(int A[row][col], int B[row][col])”
- Declare the variable “k” and “l”.
- For loop to check whether “k” is less than “row”
- For loop to check whether “j” is less than “col”
- Condition to check if both the elements in the array are equal.
- Return the value “0”.
- Condition to check if both the elements in the array are equal.
- Check whether “isTrans(A,B)” equals to 1.
- For loop to check whether “k” is less than “col”
- For loop to check whether “l” is less than “row”
- Print the element.
- Print new line.
- For loop to check whether “l” is less than “row”
- Otherwise, print the corresponding statement inside “else” clause.
- For loop to check whether “k” is less than “col”
- Define the main function
- Declare and initialize the array values.
- Declare the array “Arr_2”.
- Call the function “transpose()” by passing the array.
- Return the value “0”.
7.13
Program Plan Intro
Modified version of the exercise 7.13 with the global variables:
Program Plan:
- Include required header files.
- Declare and initialize the array as global.
- Declare the variable “n” as global variable.
- Definition for the function “sort()”.
- Declare the variables.
- Condition to check the “i<n-1”.
- Condition to check the “j<n”.
- Check whether to sort in increasing order.
- Assign “a[i] ” to “temp”.
- Assign “a[j] ” to “a[i]”.
- Assign “a[j]” to “temp”.
- Check whether to sort in decreasing order.
- Assign “a[i]” to “temp”.
- Assign “a[j] ” to “a[i]”.
- Assign “a[j]” to “temp”
- Check whether to sort in increasing order.
- Condition to check the “j<n”.
- Define the main function
- Print the statement.
- Loop to traverse the array.
- Print the element.
- Call the function “sort()”.
- Loop to traverse the array.
- Print the element.
- Print new line
- Return the value “0”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a function that use array (y) to print the result in the figure. Then write only
the call statement to call the function.
y = -3 4 0 -1 5 -6 2 8 10 -4
Location of negative numbers:
0 --> -3
3 --> -1
5 --> -6
9 --> -4
Each function deals with null terminated C-strings. You can assume that any char array passed into the functions will contain valid, null-terminated data. Your functions must have the signatures listed below.
This function returns the index in string s where the substring can first be found. For example if s is “Skyscraper” and substring is “ysc” the function would return 2. It should return -1 if the substring does not appear in the string.
int findSubstring(char *s, char substring[])
Q3] Create a new function with the name DrawHPyramid that takes one parameter r, which is the
number of rows. This function rather than using the ghạracter it uses + and - to draw the pyramid,
use recursion when implementing this function
Chapter 7 Solutions
Programming in C
Ch. 7 - Type in and run the 17 programs presented in this...Ch. 7 - Prob. 2ECh. 7 - Modify Program 7.8 so that the value of e is...Ch. 7 - Modify Program 7.8 so that the value of g is...Ch. 7 - Prob. 6ECh. 7 - Write a function that raises an integer to a...Ch. 7 - Prob. 8ECh. 7 - The least common multiple (1cm) of two positive...Ch. 7 - Prob. 10ECh. 7 - Write a function called a that takes two...
Knowledge Booster
Similar questions
- Write a function (cubeArt) to cube the first N elements in an array of doubles. The function should be passed the array and the number of elements to be cubed (the value will be replaced with its third power, e.g., if an array element is 3, it will be replaced by 27). The function should return nothing.arrow_forwardQ2: In this question, you will write a Python function to compute the Hadamard product of two matrices. The Hadamard product is the "component-wise" product of two matrices. That is, each entry of the product matrix is equal to the product of its corresponding entries of the input matrices. Here is an example: a11 a12 a21 a22 a23 a31 a13 SH a32 033 A b11 b12 b13 b21 b22 b23 b31 b32 b33. B = [an bu a21 b21 a31 b31 a12 b12 a22 b22 a32 b32 a13 b13 a23 b23 a33 b33. Hadamard product of A and B Write a Python function to compute the Hadamard product of two matrices as follows. a) The inputs to the function are two matrices. b) The function should check whether the two matrices have the same size. If not, it should print "The input matrices are not of the same size". c) If two matrices are of the same size, the function computes the Hadamard product and returns the answer. Use for loops to compute the Hadamard product.arrow_forward(Modify) Modify the program written for Exercise 9 by adding an eighth column to the array. The grade in the eighth column should be calculated by computing the average of the top three grades only.arrow_forward
- (Numerical) Given a one-dimensional array of integer numbers, write and test a function that displays the array elements in reverse order.arrow_forwardYou are designing a function that will manipulate an array of integers. It needs to work for arrays of any length. What is the minimum number of parameters your function will have?arrow_forwardComplete the function that adds 3 matrices together. The matrices will be numpy type and of the same dimension of 3 × 3. There are several ways to do this, any correct answer will be accepted. In [ ]: # add the matrices a,b,c together, these will have been passed to the function # as standard numpy matrices. Rememeber if you are unsure, just print the # elements to see how to access the matrix values. # there are several ways to do this, anyway you do this is fine import numpy as np def add_matrices(a,b,c): # initiate the matrix based on the assumption that the matrix is 3x3. matrix = np.zeros([3,3]) # your code here return matrixarrow_forward
- Write the programming language function that calls the below function appropriately, while adjusting the variables top, bottom, left and right accordingly; these 4 variables and the 2-D array should be global variables. The end result should be the array (matrix) filled in a spiral manner.arrow_forwardUsing either pseudocode of C++ code, write a function that takes three parameters and performs a sequential search. The first parameter is an array of integers. The second parameter is an integer representing the size of the array. The third parameter takes the value to be search form. The function should return the subscripts at which the value is found or -1 is the array does not contain the search term. Please dont use vectors and explain each steparrow_forwardWrite in a programming language (PL), a program to fill an NxN two- dimensional array, in a circular (spiral) pattern, with numbers from 1 to N2 as described below. You can do that by writing first the following functions/procedures which you will call in the main program. The procedure FillColumnUpward(A, top, bottom, left, z) which takes the array A the top, bottom and left as parameters and iterates through the left column from bottom to top to fill the column.arrow_forward
- Write in a programming language (PL), a program to fill an NxN two- dimensional array, in a circular (spiral) pattern, with numbers from 1 to N2 as described below. You can do that by writing first the following functions/procedures which you will call in the main program. The procedure FillRowForward(A, top, left, right, z) which takes the array A the top, left and right as parameters and iterates through top row from left to right to fill the row. z is as used in the algorithm.arrow_forwardPlease write your own code and put some commentary. Thank youarrow_forwardWrite a function to replace all the element below the main diagonal in 3x3 2D-array with zeros. Then write only the call statement to call the function.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning