[Tutorial 7] 2.Identify the syntactic errors in the following program. Then type in and run the corrected program to ensure you have correctly identified all the mistakes.
#include <stdio.h>
int main (Void)
(
INT sum;
/* COMPUTE RESULT
sum = 25 + 37 – 19
/* DISPLAY RESULTS //
printf ("The answer is %i\n" sum);
return 0;
}
- Void should be lowercase void.
- Parentheses should be used instead of curly braces for the function body.
- INT should be lowercase int.
- The calculation statement is missing a semicolon at the end.
- The comment delimiter // is incorrect; it should be /* and */.
- There is a missing comma , between the string and variable in the printf statement.
Corrected code
int main(void)
{
int sum;
/* COMPUTE RESULT */
sum = 25 + 37 - 19;
/* DISPLAY RESULTS */
printf("The answer is %i\n", sum);
return 0;
}
Comments
Post a Comment