# UVA 465 Overflow（浮点数的范围）

429人阅读 评论(0)

C - Overflow
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Appoint description:

Description

Write a program that reads an expression consisting of two non-negative integer and an operator. Determine if either integer or the result of the expression is too large to be represented as a normal'' signed integer (type integer if you are working Pascal, type int if you are working in C).

## Input

An unspecified number of lines. Each line will contain an integer, one of the two operators + or *, and another integer.

## Output

For each line of input, print the input followed by 0-3 lines containing as many of these three messages as are appropriate: first number too big'', second number too big'', result too big''.

## Sample Input

300 + 3
9999999999999999999999 + 11

## Sample Output

300 + 3
9999999999999999999999 + 11
first number too big
result too big

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define INT 2147483647
int main()
{
char s1[1000],c,s2[1000];
int l1,l2,i,j,k;
while(scanf("%s %c %s",s1,&c,s2)!=EOF)
{
double a,b;
a=atof(s1);
b=atof(s2);
printf("%s %c %s\n",s1,c,s2);
if(a>INT)printf("first number too big\n");
if(b>INT)printf("second number too big\n");

double cc;
if(c=='+')cc=a+b;
else if(c=='*')cc=a*b;
//		printf("%.0f\n",c);
if(cc>INT)printf("result too big\n");

}
return 0;
}

0
0

个人资料
• 访问：112691次
• 积分：3378
• 等级：
• 排名：第11812名
• 原创：235篇
• 转载：2篇
• 译文：0篇
• 评论：9条
阅读排行
最新评论