CHALLENGE ACTIVITY 3.13.1: Floating-point comparison: Print Equal or Not equal. Write an expression that will cause the following code to print "Equal" if the value of sensorReading is "close enough" to targetValue. Otherwise, print "Not equal". Ex: If targetValue is 0.3333 and sensorReading is (1.0/3.0), output is: Equal

Respuesta :

Answer:

The C code is given below

Explanation:

#include<stdio.h>

#include<math.h>

int main(void){

double targetValue;

double sensorReading;

scanf ("%f" , &targetValue);

scanf ("%f" , &sensorReading);

if (fabs(targetValue-sensorReading) <= 0.00004){

  // checking the absolute difference of the targetValue and sensorReading is less than or equal to 0.00004

  printf("Equal\n");

}

else {

  printf("Not Equal\n");

}

return 0;

}

fichoh

The required expression written with python.

targetValue = eval(input('Enter target value'))

sensorReading = 1.0

difference = abs(targetValue - sensorReading)

error_max = 0.00002

If difference <= error_max :

print("close enough")

else :

print("Not equal")

# targetValue holds the input target value

#sensorReading hold the sensor reading value

difference, calculate the absolute value of the difference between targetValue and sensor reading.

#error_max is the maximum error value which is can be allowed and still be deemed as close enough

#The if statement is used to evaluate the condition.

Learn more : https://brainly.com/question/14671840