The following code has 5 different errors. The errors can be any of three types,
ID: 3573900 • Letter: T
Question
The following code has 5 different errors. The errors can be any of three types, i.e., compile (compile-time and syntax errors), execution (run-time errors), or logic errors. There may be more than one error of the same type. A line may contain more than one error. Find and correct the errors in the code, i.e., write the required line(s) and the same line(s) as corrected. Assume that the proper required header files have been included./* Exchange the values in two memory locations */int main () {int a, b, c/* Prompt the user to enter the numbers. */printf (" Enter the values of a and b "); scanf ("%f %f", a, b);/* Exchange the values */a = b; c = a; b = c;/* Display the values of variables a and b */printf ("The values of a and b are: ", a, b);} Write the line(s) containing the 1^st 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) Write the line(s) containing the 5^th error and correct the line(s).Explanation / Answer
int main()
{
int a,b,c
printf("Enter the values of a and b");
scanf("%f %f", a, b);
a=b;
c=a;
b=c;
printf("The values of a and b are:", a, b);
}
1st error
int a,b,c
Expected semicolon at the end of statement
correct line
int a,b,c;
2nd error
c=a;
error is c is undeclared first use in this function
correct line
int a, b, c;
3rd error
warning message
printf("Enter the values of a and b");
incompatible implicit declaration of built-in function ‘printf’ enabled by default
we need to add #include <stdio.h> to the top of your file to rectify error
4th error
warning message
scanf("%f %f", a, b);
incompatible implicit declaration of built-in function ‘printf’ enabled by default
we need to add #include <stdio.h> to the top of your file to rectify error
5th error
while running program we are getting error as segmentation fault core dumped
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.