In: Computer Science
Identify and correct the errors in each of the following statements:
a)
printf( "The value is %d\n", &number );
b)
scanf( "%d%d", &number1, number2 );
c)
if ( c < 7 );{
printf( "C is less than 7\n" );
}
d)
if ( c => 7 ) {
printf( "C is greater than or equal to 7\n" );
a)
Answer:
printf( "The value is %d\n", &number );
&number means the adress of the number variable we have to use number
Correct statement:
printf( "The value is %d\n", number );
b)
Answer:
scanf( "%d%d", &number1, number2 );
While using scanf we have to use &variable_name to take the user input but in the above example number2 is used but we have to use &number2 to store the value in it.
Correct Statement:
scanf( "%d%d", &number1, &number2 );
C)
Answer:
if ( c < 7 );{
printf( "C is less than 7\n" );
}
In the above statemtn ; is used after the if condition which is not valid because it dont execute the code in the flower braces of we put ; beside the if conditoin
Correct statement:
if ( c < 7 ){
printf( "C is less than 7\n" );
}
d)
Answer:
if ( c => 7 ) {
printf( "C is greater than or equal to 7\n" );
In the above condition } is missing at the end of the block of the if condition
Correct statement:
if ( c => 7 ) {
printf( "C is greater than or equal to 7\n" );
}