日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/11 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 ++中的算術運算符)找到也稱為兩個數的余數模塊 。 模塊運算符使用整數值,即模數運算符用于查找兩個整數的余數。 如果數字為float或double ,則模運算符不起作用。

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中聲明。 它可用于查找float , double和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.

此處, x和y是浮點或整數值。

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 numbersint a = 10;int b = 3;// float numbersfloat m = 10.23f;float n = 3.1f;// double numbersdouble 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语言中两个浮点数或双精度数的模数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。