您的位置:首页 > 编程语言 > C语言/C++

A + B Is Overflow

2015-10-16 18:37 369 查看
Description
Judge whether the sum of A and B will exceed the range of 32-bit signed integer.

Input
There are multiple test cases. 

The first line of each test case is a positive integer T, indicating the number of test cases. 

For each test case, there is only one line including two 32-bit signed integers A and B.

Output
For each test case, output one line.

 If the sum of A and B will exceed the range of integer, print "Yes", else print "No".

Sample Input
3
1 2
-2147483648 2147483647
2147483647 2147483647

Sample Output
No
No
Yes

#include<stdio.h>

int main()

{

int t,a,b;

while(~scanf("%d",&t))

  {

 while(t--)

 {

scanf("%d%d",&a,&b);

if(a>0&b>0&&a+b<=0||a<0&&b<0&&a+b>=0)

 {

 printf("Yes\n");

 }

else{

 printf("No\n");

}

}

}

 return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言 新手 编程 acm