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
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
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