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)
- Identify and correct the mistakes in the following statements. Each statement may contain more than one mistake. scanf("%d", int); printf("%c\n", 'Hello'); printf(%f, 123.456);arrow_forwardIdentify and correct the errors in each of the following statements:a) printf( "The value is %d\n", &number );b) scanf( "%d%d", &number1, number2 );c) if ( c < 7 );{printf( "C is less than 7\n" );}d) if ( c => 7 ) {printf( "C is greater than or equal to 7\n" );}arrow_forwardPlease select all statements which one is true.arrow_forward
- Please fill in the blanks for the following statements: To input a string variable that contains white space use the ______________ function.arrow_forwardWhat is the difference between the statements continue and break?arrow_forwardFind the error (s) in each of the following program segments. Write the corrected statements and concisely explain how you corrected each.arrow_forward
- write true or false for each of the following statements:arrow_forwardAnalyze the following statements carefully and decide whether the statements that appear after the code are true or false.arrow_forwardState whether the following are true or false. If the answer is false, explain why.b) The break statement is required in the default case of a switch selection statement.arrow_forward
- 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