Please Fill out the Feedback Form for Code Radius

Sum OR Difference : DIFFSUM | CodeChef Solution

Problem

Write a program to take two numbers as input and print their difference if the first number is greater than the second number otherwise print their sum.

Please Share this article...

Input Format

  • First line will contain the first number (N1N1)
  • Second line will contain the second number (N2N2).

Output Format

Output a single line containing the difference of 2 numbers (N1 - N2)(N1−N2) if the first number is greater than the second number otherwise output their sum (N1 + N2)(N1+N2).

Constraints

−1000≤N1≤1000
-1000 \leq N2 \leq 1000−1000≤N2≤1000

Sample

Input
82 28
Output
54

Explanation

Solution

#include <iostream>
using namespace std;

// Solution from : Code Radius [ https://radiuscode.blogspot.com/ ]

int main() {
 int x,y;
	cin>>x>>y;
	if(x>y){
	    cout<<x-y<<endl;
	}
	else
	    cout<<x+y<<endl;
 return 0;
}

  import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner scan = new Scanner(System.in);
		int n1 = scan.nextInt();
		int n2 = scan.nextInt();
		System.out.println(n1>n2?n1-n2:n1+n2);
	}
}
  

  num1 = int(input())
num2 = int(input())
if num1 > num2:
    print(num1 - num2)
else:
    print(num1 + num2)
  

Please First Try to Solve Problem by Yourself.

Post a Comment

© Code Radius. All rights reserved. Distributed by Code Rdius Distributed by Pro Templates