Write a program to calculate the sum of two integers and return true if the sum is equal to a third integer.

Write a program to calculate the sum of two integers and return true if the sum is equal to a third integer.

Java Program
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        int x,y,z;
        boolean p;
        Scanner s = new Scanner(System.in);
        System.out.print("Input the first number: ");
        x = s.nextInt();
        System.out.print("Input the second number: ");
        y = s.nextInt();
        System.out.print("Input the third number: ");
        z = s.nextInt();
        p=((x + y) == z || (y + z) == x || (z + x) == y);
        if(p==true)
        {
            System.out.println("sum of two numbers equals the third number");
        }
        else
        {	
            System.out.println("sum of two numbers not equals the third number");
        }
    }
}	

Output:

Input the first number: 5
Input the second number: 10
Input the third number: 15
sum of two numbers equals the third number

Python Program
def myfun():
    x=int(input("Input the first number:  "))
    y=int(input("Input the second number:  "))
    z=int(input("Input the third number:  "))
    p=((x + y) == z or (y + z) == x or (z + x) == y);
    if(p==True):
        print("sum of two numbers equals the third number")
    else:
        print("sum of two numbers not equals the third number")
        
if __name__=="__main__":
    myfun()

Output:

Input the first number: 5
Input the second number: 10
Input the third number: 15
sum of two numbers equals the third number

C Program
#include <stdio.h>
int main() 
{
    int x,y,z,p;
    printf("Input the first number: ");
    scanf("%d",&x);
    printf("Input the second number: ");
    scanf("%d",&y);
    printf("Input the third number: ");
    scanf("%d",&z);
    p=((x + y) == z || (y + z) == x || (z + x) == y);
    if(p==1)
    {
        printf("sum of two numbers equals the third number");
    }
    else
    {	
        printf("sum of two numbers not equals the third number");
    }
    return 0;
}

Output:

Input the first number: 5
Input the second number: 10
Input the third number: 15
sum of two numbers equals the third number





More Questions


2 . Write a program to calculate the sum of two integers and return true if the sum is equal to a third integer.
3 . Write a program to check given number is Prime Number or not
4 . Write a Program to find Prime Numbers Between given Interval