Spot the errors in the following program along with labeling the type of error.
Also, write the correct code with output
#include
#include
void main()
{
Int num,den;
printf(“Enter values for two numerator and denominator”);
scanf(“%d”, &num, &den);
mod=num%den
printf(“Modulus of two numbers is %d”, mod);
}
Answers
Answer:
it is your answer...............
Explanation:
hope it helps you..............
Answer:
Errors:
#include expects "FILENAME" or
#include
^
Int num,den;
^
here it should be int
implicit declaration of function ‘printf’
printf(“Enter values for two numerator and denominator”);
^
Here The printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio. h (header file).
scanf(“%d”, &num, &den);
^
% notation is called a format specifier. %d tells printf() to print an integer.
since there are two integers that we need to take input so we need to write 2 %d's
printf(“Enter values for two numerator and denominator”);
^
here We need to use Quotation marks " " instead of “ ”
error: ‘mod’ undeclared (first use in this function)
mod=num%den
^
we need to declare the data type of mod in order to use it.
error: expected ‘,’ or ‘;’ before ‘printf’
printf("Modulus of two numbers is %d", mod);
^
after this line mod=num%den
we need to give a semi colon
Explanation :
Program with out Errors :
#include <stdio.h>
void main()
{
int num,den;
printf("Enter values for two numerator and denominator");
scanf("%d %d", &num, &den);
int mod=num%den;
printf("Modulus of two numbers is %d", mod);
}
OUTPUT:
Enter values for two numerator and denominator2 3
Modulus of two numbers is 2