A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a C++ program to check which number nearest to the value 100 among two given integers. Return 0 if the two numbers are equal
Q:

Write a C++ program to check which number nearest to the value 100 among two given integers. Return 0 if the two numbers are equal

0

Write a C++ program to check which number nearest to the value 100 among two given integers. Return 0 if the two numbers are equal

Sample Output:

95
0
99

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;

int test(int x, int y)
        {
            const int n = 100;
            int val = abs(x - n);
            int val2 = abs(y - n);

            return val == val2 ? 0 : (val < val2 ? x : y);
        }
        
int main() 
 {
  cout << test(78, 95) << endl;  
  cout << test(95, 95) << endl;  
  cout << test(99, 70) << endl;  
  return 0;    
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now