Programming in C
Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
Question
Book Icon
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”.

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”.
  • 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”.
    • 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.
      • Otherwise, print the corresponding statement inside “else” clause.
  • 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”.
  • 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”.
    • 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.
      • Otherwise, print the corresponding statement inside “else” clause.
  • 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”
  • 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”.

Blurred answer
Students have asked these similar questions
What is pass a 2D array to a functions?
Modify the selection sort function developed in this chapter so that it accepts a second optional argument, which may be either 'up' or 'down'. If the argu-ment is 'up', sort the data in ascending order. If the argument is 'down', sort the data in descending order. If the argument is missing, the default case is to sort the data in ascending order. (Be sure to handle the case of invalid arguments, and be sure to include the proper help information in your function.) Here is the given function which need to be mofified: function out = ssort(a) nvals = length(a); iptr = ii; for jj = ii+1:nvals if a(jj) < a(iptr) iptr = jj; end end if ii ~= iptr temp = a(ii); a(ii) = a(iptr); a(iptr) = temp; end end out = a;
# Write a function to copy one array to another by using pointers. Comment/Discussion on the obtained results and discrepancies (if any).
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning