c - Add floating point numbers 23.54 and 33.22 with just integral value like 23+33
问题描述
There are two floating point numbers 23.54 and 33.22 have to make a program to add them with just left side integral value like 23+33=56.
Here's the code that I tried:
解决方案
int sum;
sum=(int)num1+(int)num2;
printf("%d",sum);
or
printf("%d",(int)num1+(int)num2);
The datatype of num1 is float and I'm using (int) to typecast to integer type.
Since we typecast the datatype this is called explicit typecasting!
推荐阅读
- list - Wnat Ansible 列表输出为纯字符串
- xquery - 如何列出 MarkLogic 数据库中的所有根目录和子目录?
- python - 如何以正确的顺序打印 Scrapy 项目键?
- node.js - 数据插入后出现“结束后写入”错误
- java - KeyEvent 未运行
- python - 如何使用 Shutil 复制包含特定字符串的文件?
- python - Python 给出冗长的输出,暗示模块正在被破坏
- javascript - 不知道如何创建这个 Google chrome 扩展来获取 url
- atom-editor - 在 Atom 键盘映射中,^ 是什么意思?
- visual-studio - XAML 设计器未加载 - 通用 Windows 平台 VS2015