Sum of Two to Get Third Integer

The program must accept three integers as the input. The program must print yes if any two of the three integers can be added to obtain the remaining integer as the output. Else the program must print no as the output.

Example Input/Output:
Input:
-1 2 3

Output
yes

Explanation:
-1 + 3 = 2

Python

num1, num2, num3 = map(int, input().split())
if num1+num2 == num3 or num1+num3 == num2 or num2+num3 == num1:
print('yes')
else:
print('no')

Java

import java.util.*;
public class Hello {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num1 = sc.nextInt();
        int num2 = sc.nextInt();
        int num3 = sc.nextInt();
        if (num1 + num2 == num3 || num1 + num3 == num2 || num2 + num3 == num1) {
            System.out.print("yes");
        } else {
            System.out.print("no");
        }
    }
}

C

#include <stdlib.h>
#include  <stdio.h>
int main()
{
    int num1, num2, num3;
    scanf("%d %d %d", &num1, &num2, &num3);
    if(num1+num2 == num3 || num1+num3 == num2 || num2+num3 == num1){
        printf("yes");
    }else{
        printf("no");
    }
}

C++

#include <iostream>
using namespace std;
int main()
{
    int num1, num2, num3;
    cin >> num1 >> num2 >> num3;
    if(num1+num2 == num3 || num1+num3 == num2 || num2+num3 == num1)
    {
        cout << "yes";
    }
    else
    {
        cout << "no";
    }
    return 0;
}
Previous Article

Select By ID

Next Article

Length of the String

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *