Header Ads Widget

Sum OR Difference | 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.

Input:

  • First line will contain the first number (N1)
  • Second line will contain the second number (N2)

Output:

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

Constraints

  • 1000N11000
  • 1000N21000

Sample Input:

82
28

Sample Output:

54

Code:-

#include <iostream>
using namespace std;

int main() {
int a,b;
cin>>a>>b;
int ans;
if(a>b)
ans=a-b;
else
ans=a+b;
cout<<ans;

    return 0;
}

Recommended Post:

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

Key points:-

 MCQs:-

Post a Comment

0 Comments