Posts

Search

Z 321 Add Two Values

Given two values, they can be integer or floating point numbers, add them.
Input Format
Two values separated by a space.
Constraints
No constraints.
Output Format
One value, the result of sum of two input values.
Sample Input 0
5 4
Sample Output 0
9
Explanation 0
5 + 4 = 9

Solution(C++)

#include <iostream>
#include <algorithm>
using namespace std;
int main()
 {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */       
  double a,b,c;   
  cin>>a;   
  cin>>b;    
  c=a+b;  
  long int d=c; 
  if(c-d==0) 
   cout<<d;    
 else       
   cout<<c;  
 return 0;
}