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

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语言两个浮点数相加

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545417.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java线程的5个使用技巧

Java线程的5个使用技巧 Published: 21 Jan 2015 Category: java Java线程有哪些不太为人所知的技巧与用法&#xff1f; 萝卜白菜各有所爱。像我就喜欢Java。学无止境&#xff0c;这也是我喜欢它的一个原因。日常工作中你所用到的工具&#xff0c;通常都有些你从来没有了解过的东…

算法复习第五章贪心法

算法复习第五章贪心法概述TSP最近邻点策略最短连接策略图着色问题最小生成树&#xff08;Prim算法、Kruskal&#xff09;0-1bag问题活动安排问题多机调度概述 TSP 最近邻点策略 最短连接策略 图着色问题 最小生成树&#xff08;Prim算法、Kruskal&#xff09; 0-1bag问题 活动…

实战:定时任务案例

我在开发的时候曾经遇到了这样一个问题,产品要求给每个在线预约看病的患者,距离预约时间的前一天发送一条提醒推送,以防止患者错过看病的时间。这个时候就要求我们给每个人设置一个定时任务,用前面文章说的延迟队列也可以实现,但延迟队列的实现方式需要开启一个无限循环任…

c语言putchar函数_C语言中的putchar()函数与示例

c语言putchar函数C语言中的putchar()函数 (putchar() function in C) The putchar() function is defined in the <stdio.h> header file. putchar()函数在<stdio.h>头文件中定义。 Prototype: 原型&#xff1a; int putchar(const char *string);Parameters: co…

算法复习第六章第七章

算法复习第六章第七章第六章回溯法TSP问题0-1bag问题图着色问题八皇后问题第七章分支限界法0-1bag问题TSP问题第六章回溯法 TSP问题 0-1bag问题 图着色问题 八皇后问题 第七章分支限界法 0-1bag问题 TSP问题

扫描识别系统

扫描识别系统&#xff0c;是指能够利用扫描仪进行扫描的相关文件&#xff0c;比方普通文档&#xff0c;政府公文&#xff0c;二代身份证&#xff0c;条码……等等。通过扫描仪扫描后不单单生成常见的JPG&#xff0c;PDF等格式的图像。而是利用先进的OCR技术&#xff0c;进行相关…

转:ORA-01126: 数据库必须已装载到此实例并且不在任何实例中打开

转载&#xff1a;http://www.worlduc.com/blog2012.aspx?bid19973952 alter database archivelog 2 ; alter database archivelog * 第 1 行出现错误: ORA-01126: 数据库必须已装载到此实例并且不在任何实例中打开 ------最佳解决方案-------------------- 修改归档模式的…

Java SimpleTimeZone setStartRule()方法与示例

SimpleTimeZone类setStartRule()方法 (SimpleTimeZone Class setStartRule() method) Syntax: 句法&#xff1a; public void setStartRule(int st_mm, int st_dd, int st_time);public void setStartRule(int st_mm, int st_dd, int st_dow, int st_time);public void setSta…

实战:Redis 性能优化方案

Redis 是基于单线程模型实现的,也就是 Redis 是使用一个线程来处理所有的客户端请求的,尽管 Redis 使用了非阻塞式 IO,并且对各种命令都做了优化(大部分命令操作时间复杂度都是 O(1)),但由于 Redis 是单线程执行的特点,因此它对性能的要求更加苛刻,本文我们将通过一些优…

Python正则表达式指南上半部

本文介绍了Python对于正则表达式的支持&#xff0c;包括正则表达式基础以及Python正则表达式标准库的完整介绍及使用示例。本文的内容不包括如何编写高效的正则表达式、如何优化正则表达式&#xff0c;这些主题请查看其他教程。注意&#xff1a;本文基于Python2.4完成&#xff…

算法复习第三章分治法

算法复习第三章分治法循环日程表最近点对快速排序&#xff1a; 循环日程表 最近点对

Oracle 的 char number varchar2 效率测试

自己在建表的时候&#xff0c;用到了编号的这个字段&#xff0c; 主要问题是要用java连接数据库&#xff0c;所以要有pojo类&#xff0c; 就像 编号 这种字段&#xff0c;int 不够&#xff0c;long 转起来麻烦&#xff0c;还容易出错。 突然想看看char可不可以&#xff0c;所…

实战:Redis 慢查询

Redis 慢查询作用和 MySQL 慢查询作用类似,都是为我们查询出不合理的执行命令,然后让开发人员和运维人员一起来规避这些耗时的命令,从而让服务器更加高效和健康的运行。对于单线程的 Redis 来说,不合理的使用更是致命的,因此掌握 Redis 慢查询技能对我们来说非常的关键。 …

Java SecurityManager checkAccess()方法与示例

Syntax: 句法&#xff1a; public void checkAccess (Thread th);public void checkAccess (ThreadGroup tg);SecurityManager类的checkAccess()方法 (SecurityManager Class checkAccess() method) checkAccess(Thread th) method is called for the current security manage…

算法复习第四章动态规划

算法复习第四章动态规划动态规划TSP问题0-1bag动态规划 TSP问题 0-1bag 最长公共子序列不考&#xff1a;

4. 星际争霸之php设计模式--工厂方法模式

题记本php设计模式专辑来源于博客(jymoz.com)&#xff0c;现在已经访问不了了&#xff0c;这一系列文章是我找了很久才找到完整的&#xff0c;感谢作者jymoz的辛苦付出哦&#xff01; 本文地址&#xff1a;http://www.cnblogs.com/davidhhuan/p/4248177.html PHP手册上提到的工…

Oracle 建立序列以及触发器的建立

笔记系列 序列&#xff1a;序列的创建方法&#xff0c;以及插入数据时的使用&#xff1b; --序列的创建 create sequence sq increment by 1 start with 1 maxvalue 10 minvalue 1 cycle cache 5--一般(一个序列可以用在多张表&#xff0c;但是一般情况下&#xff0c;一张表对应…

实战:Redis 性能测试

为什么需要性能测试? 性能测试的使用场景有很多,例如以下几个: 技术选型,比如测试 Memcached 和 Redis;对比单机 Redis 和集群 Redis 的吞吐量;评估不同类型的存储性能,例如集合和有序集合;对比开启持久化和关闭持久化的吞吐量;对比调优和未调优的吞吐量;对比不同 R…

操作系统Ubuntu(实验三四)

实验三四3._实验三&#xff1a;Linux进程/线程的异步并发执行3.1_fork()函数创建子进程3.2_创建线程pthread_create();4._实验四&#xff1a;使用信号量进行互斥与同步4.1_信号量初使用&#xff08;1&#xff09;信号量简单介绍&#xff08;2&#xff09;信号量以及P、V操作的使…

Java RandomAccessFile writeShort()方法与示例

RandomAccessFile类writeShort()方法 (RandomAccessFile Class writeShort() method) writeShort() method is available in java.io package. writeShort()方法在java.io包中可用。 writeShort() method is used to write the short value to the file as 2 bytes directly wi…