top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

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

0 votes

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;
    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

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.