﻿ C++ Exercises: Check three given integers and return true if one of them is 20 or more less than one of the others - w3resource # C++ Exercises: Check three given integers and return true if one of them is 20 or more less than one of the others

## C++ Basic Algorithm: Exercise-48 with Solution

Write a C++ program to check three given integers and return true if one of them is 20 or more less than one of the others.

Sample Solution:

C++ Code :

``````#include <iostream>
using namespace std;

bool test(int x, int y, int z)
{
return abs(x - y) >= 20 || abs(x - z) >= 20 ||
abs(y - z) >= 20;
}

int main()
{
cout << test(11, 21, 31) << endl;
cout << test(11, 22, 31) << endl;
cout << test(10, 20, 15) << endl;
return 0;
}
``````

Sample Output:

```1
1
0
```

Pictorial Presentation: Flowchart: C++ Code Editor:

Contribute your code and comments through Disqus.

What is the difficulty level of this exercise?

﻿
{"ft_lang_label":"__label__en","ft_lang_prob":0.66438466,"math_prob":0.947576,"size":1573,"snap":"2021-04-2021-17","text_gpt3_token_len":394,"char_repetition_ratio":0.13193117,"word_repetition_ratio":0.13309352,"special_character_ratio":0.28035602,"punctuation_ratio":0.12631579,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.997611,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,null,null,5,null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-04-13T18:37:00Z\",\"WARC-Record-ID\":\"<urn:uuid:9f4b319a-434e-4a29-9a88-b93d20a618f2>\",\"Content-Length\":\"126253\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1c8a5d0e-b9a8-4ee0-83a8-b923d9681992>\",\"WARC-Concurrent-To\":\"<urn:uuid:143b0c57-60eb-47b8-8986-0b6911dcf3e3>\",\"WARC-IP-Address\":\"172.67.69.127\",\"WARC-Target-URI\":\"https://www.w3resource.com/cpp-exercises/basic-algorithm/cpp-basic-algorithm-exercise-48.php\",\"WARC-Payload-Digest\":\"sha1:UJA7MT4WA4SGHBRCPQEX6EXFI3Z4FO74\",\"WARC-Block-Digest\":\"sha1:V5675CJO2NGOIBUBBTLG4UL643SSVW6Z\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-17/CC-MAIN-2021-17_segments_1618038074941.13_warc_CC-MAIN-20210413183055-20210413213055-00404.warc.gz\"}"}