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
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out With Visual Basic (7th Edition)
Programming in C
Computer Science: An Overview (12th Edition)
C Programming Language
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- State whether each of the following is true or false. If false, explain why j) The arithmetic operators *, /, %, + and - all have the same level of precedence.arrow_forwardIdentify and correct the mistakes in the following statements. Each statement may contain more than one mistake. scanf("%d, %d, %d", &x &y &z ); The following statement should print "Bon Voyage":printf(""%s"", "Bon Voyage");arrow_forwardplease quickly thanks !! use Pythonarrow_forward
- Note: write a C program and format use in Program (Printf & Scanf) Question # 2: Sacha Sweets and Bakers is a popular baker. The store has multiple sections for Cakes, Cupcakes, Brownies, Savory Items, Chips and Nimco. Currently, the store maintains a manual register for recording the details of the bake items such as type, price, orderQty, sales, and so on. However, the owner of the store has decided to automate the tasks such as data entry, sales calculation, stock updation, and so on to save time and effort required in the tasks. You as a software developer have to accomplish the task as follows: You have to create structure for user in which you store user details. Structure has four members: name, city, CNICno and phoneNo. First you have to show menu to user with different categories including subcategories, for this write function for show menu. Every category have different items…arrow_forwardc++ languagearrow_forward5) Analyze the following code: boolean even = ((240 % 2) = 0): if (even) System.out.println("It is even!"): a. The program has a syntax error b. The program has a runtime error c. The program displays “It is odd!" d. d. The program displays "It is even!" else Page 2 of 6 System.out.println("It is odd!");arrow_forward
- NB: USE IF ELSE STATEMENTS FOR THIS CODING IN C++ • Calculate each student's grade - 10 students in a class; each student has taken five tests; each test is worth 100 points • Design algorithms to: - Calculate the grade for each student and class average - Find the average test score - Determine the grade • Data: students' names; test scoresarrow_forwardFor each of the following statements, state whether it is True or False.arrow_forwardMatlabarrow_forward
- Functions Exercise (Parking Charges) A parking garage charges a $2.00 minimum fee to park for one hour. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a neat tabular format and should calculate and print the total of yesterday's receipts. The program should use the function Charge to determine the charge for each customer. Car Hours Charge 1 2 Computer skills (Engineering) 3 1 4 24 TOTAL 2 8 10 20arrow_forwardCorrect the following wrong statements. All binary operators except for the assignment operators are evaluated as user intention.arrow_forwardNonearrow_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 Ptr