现在的位置: 首页 > 综合 > 正文

UVA465

2013年09月14日 ⁄ 综合 ⁄ 共 564字 ⁄ 字号 评论关闭

思路:使用atof函数,将字符串改成浮点数,这样就可以直接计算以及判断了

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 800 
int main(){
	char s1[N], s2[N];
	char ch;
	double a;
	while (scanf("%s %c %s", s1, &ch, s2) != EOF){
		printf("%s %c %s\n", s1, ch, s2);	
		if (atof(s1) > 2147483647)	
			printf("first number too big\n");
		if (atof(s2) > 2147483647)
			printf("second number too big\n");
		if (ch == '+')
			a = atof(s1) + atof(s2);
		else if (ch == '*')
			a = atof(s1) * atof(s2);
		if (a > 2147483647)
			printf("result too big\n");
	}
	return 0;
}

/*取值范围:
  int :-2147483648 到 +2147483647
  long :-9223372036854775808 到 +9223372036854775807
  float :1.5*10-45  到 3.4*1038
  double:5.0*10-324  到 1.7*10308*/

抱歉!评论已关闭.