Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 7, Problem 13E
Program Plan Intro
Program Plan:
- Include required header files
- 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
- Declare the required variable
- Initialize the array.
- 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
c++
1. Use the rand() function (seeded with srand(time(0))) to generate a small arrays of dimension 20, such that the entries are random positive integers less than 100. Implement the bubble sort and the selection sort and sort your random array of integers.
5. Using c++, Write a function that determines the index of the second to the last occurrence of a target b in an integer array a. Return -1 if b is not in a or there is only 1 occurrence of b in a.
Write a function to sort data (in increasing order) in an array using
a. pass by value
b. and pass by reference.
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
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- e. Write down the algorithm for binary search.f. Using binary search, write a program in c++ that will search through any given nth numberof values in an array.arrow_forwardWrite a C function to search for a given number using binary search in a given array ofsorted numbers, sorted in ascending order. The function should return the index wherethe number is found, or zero otherwisearrow_forwardWrite a recursive function to implement the recursive algorithm of Exercise 16 (reversing the elements of an array between two indices). Also, write a program to test your function.arrow_forward
- write a c++ program to ask user to enter two sorted arrays We need to merge these two arrays such that the initial numbers (after completesorting) are in the first array and the remaining numbers are in the second array.arrow_forward5. Implement the binary search function below that returns the index of the target value in an integer array. int search(int a[], int t, int l, int r); Given the binary search function in question 5 and the array a below, list all activations when calling search(a, 19, 0 15). -9 -5 -2 0 1 3 7 11 17 19 21 25 27 31 37 41 a index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15arrow_forwardWrite a program to sort the elements of 1 D array in descending order and also implement linear search on the same array. Both sorting and searching should be done inside one user defined function: Task. So for achieving the required functionality, pass array into function: Task () from main () using pass by reference/ or address approacharrow_forward
- Write a program using function to find the value of array C from add array A and array B. C[ i ] = A [ i] + B[i];arrow_forward(Practice) a. Write a C++ program that adds the values of all elements in the val array used in Exercise 2 and displays the total. b. Modify the program written for Exercise 3a to display the total of each row separately.arrow_forwardQ1. Write a program to sort the elements of 1D array in descending order and also implement linear search on the same array. Both sorting and searching operations should be done inside one user defined function: “Task”. So, for achieving the required functionality, pass, array into the function: Task () from main () using Pass by reference/ or address approach.arrow_forward
- Complete the swift function given below and test it for the array [14, 67, 4, 16]arrow_forwardYou are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n. Solution should avoid Runtime Errorarrow_forwardYou are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n.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