
Identify and correct the errors in each of the following statements. (Note: There may be more than one error per statement.)
(a)

To identify and correct the error in the following statement.
scanf(“%d”, value);
Explanation of Solution
Given information:
scanf(“d”, value);
Explanation:
Format specifier missing %d is used to take integer type value from the user. Missing percentage symbol % to be placed before the format specifier d.
Correct statement:
scanf(“%d”, value);
(b)

To identify and correct the error in the following statement.
printf(“The product of %d and %d is %d\n”,x,y);
Explanation of Solution
Given information:
printf(“The product of %d and %d is %d”\n,x,y);
Explanation:
The \n is escape sequence used to assign a new line. All the escape sequences used inside the double quotes (“”) of printf statement. Here, the escape sequence is out of the double quotes area. To correct this statement, make \n inside the double quotes area.
Correct statement:
printf(“The product of %d and %d is %d\n”,x,y);
(c)

To identify and correct the error in the following statement.
sumOfNumbers=firstNumber + secondNumber;
Explanation of Solution
Given information:
firstNumber + secondNumber = sumOfNumbers
Explanation:
The associativity of equals to (=) operator is right to left so that it will first calculate firstNumber + secondNumber, then assign this value in sumOfNumbers. Also, semicolon (;) missing at the end of the statement.
Correct statement:
sumOfNumbers = firstNumber + secondNumber;
(d)

To identify and correct the error in the following statement.
if(number >= largest)
largest=number;
Explanation of Solution
Given information:
if(number => largest)
largest==number;
Explanation:
The operator Greater then or equals to having a wrong syntax (=>), correct syntax should be (>=). Comparison operator is used instead of the assignment operator (=).
Correct statement:
if(number >= largest)
largest=number;
(e)

To identify and correct the error in the following statement.
/* Program to determine the largest of the integer */
Explanation of Solution
Given information:
*/ Program to determine the largest of the integer /*
Explanation:
Wrong syntax of multiline comment, the correct syntax should be: -
/* some-comment */
Correct statement:
/* Program to determine the largest of the integer */
(f)

To identify and correct the error in the following statement.
scanf(“%d”, &anInteger);
Explanation of Solution
Given information:
Scanf(“%d”, anInteger);
Explanation:
The initial of Scanf keyword should be lowercase. The ampers and (&) required before anInteger.
Correct statement:
scanf(“%d”, &anInteger);
(g)

To identify and correct the error in the following statement.
printf(“Remainder of %d division by %d is %d\n”, x, y, x%y);
Explanation of Solution
Given information:
printf(“Remainder of %d division by %d is\n”, x, y, x%y);
Explanation:
Format %dspecifier needed to print the value of x%y.
Correct statement:
printf(“Remainder of %d division by %d is %d\n”, x, y, x%y);
Want to see more full solutions like this?
Chapter 2 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
SURVEY OF OPERATING SYSTEMS
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Degarmo's Materials And Processes In Manufacturing
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
- a) first player is the minimizing player. What move should be chosen?b) What nodes would not need to be examined using the alpha-beta pruning procedure?arrow_forwardConsider the problem of finding a path in the grid shown below from the position S to theposition G. The agent can move on the grid horizontally and vertically, one square at atime (each step has a cost of one). No step may be made into a forbidden crossed area. Inthe case of ties, break it using up, left, right, and down.(a) Draw the search tree in a greedy search. Manhattan distance should be used as theheuristic function. That is, h(n) for any node n is the Manhattan distance from nto G. The Manhattan distance between two points is the distance in the x-directionplus the distance in the y-direction. It corresponds to the distance traveled along citystreets arranged in a grid. For example, the Manhattan distance between G and S is4. What is the path that is found by the greedy search?(b) Draw the search tree in an A∗search. Manhattan distance should be used as thearrow_forwardwhats for dinner? pleasearrow_forward
- Consider the follow program that prints a page number on the left or right side of a page. Define and use a new function, isEven, that returns a Boolean to make the condition in the if statement easier to understand. ef main() : page = int(input("Enter page number: ")) if page % 2 == 0 : print(page) else : print("%60d" % page) main()arrow_forwardWhat is the correct python code for the function def countWords(string) that will return a count of all the words in the string string of workds that are separated by spaces.arrow_forwardConsider the following program that counts the number of spaces in a user-supplied string. Modify the program to define and use a function, countSpaces, instead. def main() : userInput = input("Enter a string: ") spaces = 0 for char in userInput : if char == " " : spaces = spaces + 1 print(spaces) main()arrow_forward
- What is the python code for the function def readFloat(prompt) that displays the prompt string, followed by a space, reads a floating-point number in, and returns it. Here is a typical usage: salary = readFloat("Please enter your salary:") percentageRaise = readFloat("What percentage raise would you like?")arrow_forwardassume python does not define count method that can be applied to a string to determine the number of occurances of a character within a string. Implement the function numChars that takes a string and a character as arguments and determined and returns how many occurances of the given character occur withing the given stringarrow_forwardConsider the ER diagram of online sales system above. Based on the diagram answer the questions below, a) Based on the ER Diagram, determine the Foreign Key in the Product Table. Just mention the name of the attribute that could be the Foreign Key. b) Mention the relationship between the Order and Customer Entities. You can use the following: 1:1, 1:M, M:1, 0:1, 1:0, M:0, 0:M c) Is there a direct relationship that exists between Store and Customer entities? Answer Yes/No? d) Which of the 4 Entities mention in the diagram can have a recursive relationship? e) If a new entity Order_Details is introduced, will it be a strong entity or weak entity? If it is a weak entity, then mention its type?arrow_forward
- No aiarrow_forwardGiven the dependency diagram of attributes {C1,C2,C3,C4,C5) in a table shown in the following figure, (the primary key attributes are underlined)arrow_forwardWhat are 3 design techniques that enable data representations to be effective and engaging? What are some usability considerations when designing data representations? Provide examples or use cases from your professional experience.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTNp Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage



