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 6, Problem 2E
Program Plan Intro
- Include required header files.
- Declare the function “main ()”.
- Declare an array named “values []” with size 10.
- Declare a variable named “index”.
- Loop from “0” through the size of the array using “for” loop.
- Set the array index to 0.
- Loop from “0” through the size of the array using “for” loop.
- Display the array values using “printf ()” statement.
- Return the statement.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Using C++
Write a C++ program that takes an array as input from the user. Then, remove the duplicate elements in the array and also display the new array and its size [size of actual/unique elements] of array.
Note: Use nested loop, a duplicate value will be shifted to the end of array. The size of array will decrease with every duplicate value.
Write these in Pseudocode
#1a – In pseudocode, write a call to a function that passes 1 Integer variable and 1 Integer array, and saves a Boolean value in return.
#1b – In pseudocode, write the function that accepts 1 Integer and 1 Integer array and returns a Boolean.
In the function, search the Integer array with a for-loop, and if the Integer parameter is found in the array, return false. If the Integer parameter is not found, return true.
#2a – In pseudocode, write a call to a module that passes 1 Integer variable, 1 Real variable, 1 String constant, and 1 String literal as arguments.
#2b – In pseudocode, write the module header that accepts 1 Integer, 1 Real, and 2 Strings as parameters.
#3 – This pseudocode has multiple problems. Fix the calling statement and the definition below so that the routine accepts 3 grades as parameters and returns the average into a variable.…
Chapter 6 Solutions
Programming in C
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
- How many times does a for loop run? A. A for loop runs a random number of times. B. The value of the for loop variable defines the number of times a for loop may run. C. A for loop runs once. D. A for loop runs once for each item in the sequence included in the for statement. How do the lines of code in the body of a function get executed? A. As soon as the function is defined the code is executed B. The function must be called within the program C. The name of the function is passed in the exec command D. Based on the function's condition What happens when a function is called? A. The function is defined. B. The function is deleted. C. Program execution jumps to the function definition and executes the code in the function body. D. All of the above.arrow_forward. Write a program in C to convert a binary number into a decimal number without using array, function and while loop. Test Data :Input a binary number :1010101Expected Output :The Binary Number : 1010101The equivalent Decimal Number : 85arrow_forwardIn c++ Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, th backwards End each loop with a newline. Ex If courseGrades (7, 9, 11, 10), print: 7 9 11 10 10 11 9 7 Hint Use two for loops. Second loop starts with i=NUM VALS-1. (Notes) Note: These activities may test code with different test values. This activity will perform two tests, both with a 4-element array (int courseGrades(4) See 'How to Use zyBooks Also note: If the submitted code tries to access an invalid array element, such as courseGrades[9] for a 4-element array, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message 32344345730rity? 2 using namespace std; 3 4 int main() { 5 6 7 8 9 10 11 12 13 14 const int NUM VALS-4; int courseGrades [NUM VALS]; int i; for (i = 0; i > courseGrades[1]; } y Your solution goes here Yarrow_forward
- Write a C++ program that takes an char array of size twenty. Take input a sorted array from the user. Display the char array on console such that each row has only five elements separated by spaces. Then, you are required to then take a char x from the user and use binary search to search for element x in the array. Display the index of the element on the console. Also display two elements before and after the element x. Note: Don't use functions and strings.arrow_forwardWrite a program in C++ to find the transpose of a 3x3 matrix input by the user, store it in another array and display it. instructions: 1.avoid void function in the program. 2. use int function. 3. avoid copy-pasting and plagiarism 4. write a self-written code 5. give comments with each step. 6. write code with easy and basic steps as I am just a student.arrow_forwardThis is done in Perl. Take in a series of positive integers from the user, stopping when they enter a zero, and store them into an array. a) Use a for each loop to print the square of each number if the square is between 100 and 200. b) Use the map and grep functions to do the same as in (a).arrow_forward
- In PYTHON (Sum the major diagonal in a matrix) Write a function that sums all the numbers of the major diagonal in an n × n matrix of integers using the following header:def sumMajorDiagonal (m):The major diagonal is the diagonal that runs from the top left corner to the bottom right corner in the square matrix. Write a test program that reads a 4 × 4 matrix and display the sum of all its elements on the major diagonal.Program Sample Run (With Input Shown in Bold)Enter a 4-by-4 matrix row 0: 1 2 3 4Enter a 4-by-4 matrix row 1: 5 6.5 7 8Enter a 4-by-4 matrix row 2: 9 10 11 12Enter a 4-by-4 matrix row 3: 13 14 15 16Sum of the elements in the major diagonal is 34.5arrow_forward2. Fill in the for-loop below with the correct parameters to make room for the new value. saved Let's say that you have to write a function to insert an element into an ordered array. It takes an array A, a size, an index and a value. The value needs to be inserted at Aſindex] without losing values that are already in the array. // Assume that the index is found to be within array bounds and there is room to insert. for (int i = ?; ?; ?) { A[i]=A[i-1]; } A[index]=value; size++; O 0; i 0; - O size; i> index; -- O size-1; i>= index; i--arrow_forwardCan you please help me write the code in C++? It needs to be exactly wrote like the example in black. Also, if you can include a random number generator between [1,9] for the Matrixes then, that would be great. Note: Use DO-WHILE loop to verify user input for scale factor.arrow_forward
- : A monochrome screen is stored as a single array of bytes, allowing eight consecutivepixels to be stored in one byte. The screen has width w, where w is divisible by 8 (that is, no byte willbe split across rows). The height of the screen, of course, can be derived from the length of the arrayand the width. Implement a function that draws a horizontal line from (xl, y) to (x2, y).The method signature should look something like:drawLine(byte[] screen, int width, int xl, int x2, int y)arrow_forwardCan you help me atleast just the main function?arrow_forwardWrite a c++ program that inputs the scores of hoops made of five players on two separate teams in a basketball shootoff game --- Team A and Team B. An array for each team should be declared and the scores entered using a separate for loop for each team. The program should then compare the scores head-to-head for each particular player for each team. For example ---The score for player 1 for team A should be compared to the score for player 1 on team B, The score for player 2 for team A should be compared to the score for player 2 on team B, The score for player 3 for team A should be compared to the score for player 3 on team B, etc. The program should determine which team one in two separate ways ---- a) Which team won the most head-to-head shootoff hoops, and b) Whch team overall scored the most hoops.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