65_转换函数

//_65_转换函数
//_65_main.cpp

/*在头文件<stdlib.h>中
将str指向的串转换成双精度浮点值、整型值、长整型值
串中必须含有合法的xxxxxx、xxx、xxxx,一一对应
double atof(const char *str);
int atoi(const char *str);
long int atol(const char *str);
*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
	char num1[80],num2[80];
	printf("Enter first: ");
	gets(num1);
	printf("Enter second: ");
	gets(num2);
	double doubleSum1 = atof(num1);
	double doubleSum2 = atof(num2); 
	double doubleSum3 = doubleSum1 + doubleSum2;
	printf("atof(num1) is: %f\n",doubleSum1);
	printf("atof(num2) is: %f\n",doubleSum2);
	printf("The sum of num1 and num2 is: %f\n",doubleSum3);

	printf("Enter third: ");
	gets(num1);
	printf("Enter fourth: ");
	gets(num2);
	int intSum1 = atoi(num1);
	int intSum2 = atoi(num2);
	int intSum3 = intSum1 + intSum2;
	printf("atoi(num1) is: %f\n",intSum1);
	printf("atoi(num2) is: %f\n",intSum2);
	printf("The sum of num1 and num2 is: %f\n",intSum3);

	printf("Enter fifth: ");
	gets(num1);
	printf("Enter sixth: ");
	gets(num2);
	long int longSum1 = atol(num1);
	long int longSum2 = atol(num2);
	long int longSum3 = longSum1 + longSum2;
	printf("atol(num1) is: %f\n",longSum1);
	printf("atol(num2) is: %f\n",longSum2);
	printf("The sum of num1 and num2 is: %f\n",longSum3);

	system("pause");
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值