c语言两个浮点数相加

As we know that modules also known as the remainder of the two numbers can be found using the modulus (%) operator which is an arithmetic operator in C/C++. The modules operator works with integer values i.e. modulus operator is used to find the remainder of two integer numbers. If the numbers are float or double the the modulus operators doesn't work.

我们知道,也可以使用模数 ( )运算符(也就是C / C ++中的算术运算符)找到也称为两个数的余数模块模块运算符使用整数值,即模数运算符用于查找两个整数的余数。 如果数字为floatdouble ,则运算符不起作用。

Consider the below example,

考虑下面的示例,

#include <stdio.h>
int main()
{
float x = 10.23f;
float y = 3.1f;
float result = x % y;
printf("result = %f\n", result);
return 0;
}

Output:

输出:

main.c: In function ‘main’:
main.c:8:22: error: invalid operands to binary % (have ‘float’ and ‘float’)
float result = x % y;
^

See the output – it says that invalid operands to modulus operator.

看到输出–它表示模数运算符的无效操作数。

Then, how to find the remainder/modulus of two float or double numbers?

然后, 如何找到两个浮点数或双数的余数/模数?

There is a library function remainder(), declared in math.h. It can be used to find the modules of float, double, and integer (also) numbers.

有一个库函数restder() ,在math.h中声明。 它可用于查找floatdouble和integer(也)数字的模块。

The remainder() function accepts two parameters and returns the remainder.

restder()函数接受两个参数并返回剩余的值。

Syntax:

句法:

remainder(x, y);

Here, x and y are the floating-point or integral values.

此处, xy是浮点或整数值。

Example 1:

范例1:

#include <stdio.h>
#include <math.h>
int main()
{
float x = 10.23f;
float y = 3.1f;
float result = remainder(x, y);
printf("result = %f\n", result);
return 0;
}

Output:

输出:

result = 0.930000

Example 2:

范例2:

#include <stdio.h>
#include <math.h>
int main()
{
// integer numbers
int a = 10;
int b = 3;
// float numbers
float m = 10.23f;
float n = 3.1f;
// double numbers
double x = 123456789.10;
double y = 1233.1;
printf("remainder(%d,%d) = %lf\n", a, b, remainder(a, b));
printf("remainder(%f,%f) = %lf\n", m, n, remainder(m, n));
printf("remainder(%lf,%lf) = %lf\n", x, y, remainder(x, y));
return 0;
}

Output:

输出:

remainder(10,3) = 1.000000
remainder(10.230000,3.100000) = 0.930000
remainder(123456789.100000,1233.100000) = 50.200000

翻译自: https://www.includehelp.com/c/modulus-of-two-float-or-double-numbers-in-c-language.aspx

c语言两个浮点数相加

c语言两个浮点数相加_C语言中两个浮点数或双精度数的模数相关推荐

  1. c语言正数与负数相加_C语言数据基本类型(1)

    1.原码:一个数的原码(原始的二进制码)有如下特点: 最高位做为符号位,0表示正,为1表示负 其它数值部分就是数值本身绝对值的二进制数 负数的原码是在其绝对值的基础上,最高位变为1 注:原码表示法简单 ...

  2. 阿里开发者招聘节 | 面试题14:如何实现两金额数据相加(最多小数点两位)

    为帮助开发者们提升面试技能.有机会入职阿里,云栖社区特别制作了这个专辑--阿里巴巴资深技术专家们结合多年的工作.面试经验总结提炼而成的面试真题这一次将陆续放出(面试题官方参考答案将在专辑结束后统一汇总 ...

  3. 二维数组c语言矩阵加法,C 语言实例 – 两个矩阵相加 - C 语言基础教程

    C 语言实例 使用多维数组将两个矩阵相加. #include int main(){ int r, c, a[100][100], b[100][100], sum[100][100], i, j; ...

  4. c语言 字符相加_C语言中自加自减的编译原理

    自增自减规则 i++ 与 ++i 的主要区别有两个: 1. i++ 返回原来的值,++i 返回加1后的值. 2. i++ 不能作为左值,而++i 可以. 毫无疑问大家都知道第一点(不清楚的看下下面的实 ...

  5. 数组两个整数相加 c语言,作业帮:给定一个整数数组,找出其中两个数相加等于目标值(去重set)...

    题目描述 给定一个整数数组,找出其中两个数相加等于目标值 输入 [1,3,5,7,9,11] 10 输出 1,9 3,7 代码: import java.util.HashMap; import ja ...

  6. c语言代码大全表解释_C语言常用错误代码释义大全,值得收藏!

    对于刚学编程,刚接触C++的新手来说,编译运行报错是最头疼的一件事,爆出一堆英文,英语差一点的又不知道什么意思,所以也不知道如何去改,在此,我给大家传一份常见错误中英文对照表及简单解释,希望可以帮到大 ...

  7. vc 运行c语言步骤,第1章_C语言概述(vc++环境如何运行c语言程序)[精选].ppt

    第1章_C语言概述(vc环境如何运行c语言程序)[精选] C语言程序设计 授课对象:电子商务06 时间安排: 理论课(1-9周): 星期一 5-6节 9407D 星期三 5-6节 9410D 实验课( ...

  8. c程序设计语言 qsort,【程序设计基础_C语言】北理工的恶龙(附qsort范例)

    [程序设计基础_C语言]北理工的恶龙(附qsort实例) 北理工的恶龙(附qsort实例) 背景:最近,北理工出现了一只恶龙,它长着很多 头,而且还会吐火,它将会把北理工烧成废墟, 于是,校长下令召集 ...

  9. 【C语言 MOOC】程序设计入门_C语言(翁恺)

    文章目录 程序设计入门-C语言(MOOC-翁恺) Week 1 程序设计与C语言 lesson 1 计算机和编程语言 辗转相除法 程序的执行 lesson 2 第一个程序 Week 2 计算 less ...

最新文章

  1. Auty 2017——WebMonitor接口线上检测平台
  2. keras 的 example 文件 class_activation_maps.py 解析
  3. 一文读懂Python版的十大经典排序算法(附动图演示)
  4. ArrayList和LinkedList的add(E)性能秘密
  5. 【转】每天一个linux命令(44):top命令
  6. linux Makefile编写的整理
  7. java u003_我在B站学编程 DAY-003 JAVA基础概念和语法
  8. 简述Qt编程中遇到的编码格式问题
  9. EntityFramework进阶——数据编辑与维护
  10. 图片压缩软件_简单易用的图片压缩软件gt;给图片减肥
  11. 想要学习UI动效设计?从这些软件入手
  12. 拆分器控件Splitcontainer
  13. mybatis多表联合查询
  14. python爬取微博热搜显示到折线图_Python爬取新浪微博热搜榜-Go语言中文社区
  15. OpenCV定位二维码的三个定位点
  16. 立创EDA安装ibom插件
  17. No enclosing instance of type testTry is accessible. Must qualify the allocation...之解决方法
  18. .NET使用MailKit进行邮件处理
  19. 【安全资讯】数据泄露、数据窃听,如何保障大数据时代的信息安全
  20. QQ红包终于支持微信支付了

热门文章

  1. f3arra1n3.4.1版本_Sysmon v11.1新版本功能测试报告
  2. python axis 0 1_python pandas 中axis值0 1怎么分行还是列
  3. python涉及到的逻辑_涉及逻辑运算的python表达式的运算顺序
  4. logstash-input-redis源码解析
  5. drbd(三):drbd的状态说明
  6. mac自己定义tree命令
  7. 清理vs工程文件(python2.7)
  8. ppp和chap的区别
  9. 微软中文网,越办越好了!
  10. centos一键安装redmine