top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Write a C program where two values are compared to third value and nearest value is returned?

0 votes
597 views

a and b are compared against
the threshold ‘TH’, and the nearest value is voted as output

posted May 28, 2018 by Sushma R

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
int compare (int a, int b, int th) 
{
  if (abs(th - a) > abs(th-b))
    return b;
  else
    return a;
}

if a and b both are at the same distance from th then a is returned.

answer May 28, 2018 by Salil Agrawal
Similar Questions
+2 votes

How can I wwap value two variables without using third variable or +/- operator?

+1 vote

Input : Query Home is a good website

Output: Query Home is a very good website

...