[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;

}

  1. Void should be lowercase void.
  2. Parentheses should be used instead of curly braces for the function body.
  3. INT should be lowercase int.
  4. The calculation statement is missing a semicolon at the end.
  5. The comment delimiter // is incorrect; it should be /* and */.
  6. There is a missing comma , between the string and variable in the printf statement.
Corrected code

#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;
}

Comments

Popular posts from this blog

Introduction To C

First C Program

Compilation process in c