Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following code has 5 different errors. The errors can be any of three types,

ID: 3574469 • Letter: T

Question

The following code has 5 different errors. The errors can be any of three types, i.e., (compile-time and syntax errors), execution (run-time errors), or logic errors. There may be more than one error the same type. A line may contain more than one error. Find correct the errors in the code, i.e., write the incorrect line(s) and the same line(s) as corrected. Assume that the proper required header files have been included. write the line(s) containing the 1^st error and error and correct the line(s). Write the line(s) containing the 2^nd error and correct the line(s). Write the line(s) containing the 3^rd error and correct the line(s). Write the line(s) containing the 4^th error and correct the line(s).

Explanation / Answer

Incorrent Line : int main ( ) ;

Correct Line : int main ( )

Incorrent Line : printf(" Enter two integers: ");

Correct Line :   printf(" Enter two integers: ");

Incorrent Line : scanf("%lf %lf",&nbr1,&nbr2);

Correct Line : scanf("%d %d",&nbr1,&nbr2);

Incorrent Line : printf(" The average is: ",avg);

Correct Line : printf(" The average is: %f",avg);

Incorrent Line : avg = nbr1 + nbr2 / 2;

Correct Line : avg = (nbr1 + nbr2 ) / 2;

The correct code with all the changes is provided below:

#include <stdio.h>
int main ()
{
   int nbr1,nbr2;
   float avg;
   printf(" Enter two integers: ");
   scanf("%d %d",&nbr1,&nbr2);
   avg=(nbr1+nbr2)/2;
   printf(" The average is: %f",avg);
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote