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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

c语言中负数_C语言中负数的模数

發布時間:2023/12/1 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言中负数_C语言中负数的模数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

c語言中負數

C中的模數運算符(%)運算符 (The modulus operator (%) operator in C)

The modulus operator is an arithmetic operator in C language; it is a binary operator and works with two operands. It is used to find the remainder.

模運算符是C語言中的算術運算符; 它是一個二進制運算符,并且可以使用兩個操作數。 它用于查找余數。

Syntax:

句法:

operand1 % operand2;

It returns the remainder which comes after dividing operand1 by operand2.

它返回它來除以操作數由操作數后的余數。

Example:

例:

Input:int a = -10;int b = 3;// finding remainderresult = a%b;printf("result = %d\n", result);Output:result = -1

C code to demonstrate example of modulus operator with positive operands

C代碼演示具有正操作數的模運算符的示例

// C program to demonstrate example of // Modules operator (%)#include <stdio.h>int main() {int a = 10;int b = 3;int result;result = a%b;printf("result = %d\n", result);return 0; }

Output

輸出量

result = 1

負數的模運算符 (Modulus operator with negative numbers)

If we have negative numbers, the result will be based on the left operand's sign, if the left operand is positive – the result will be positive, and if the left operand is negative – the result will be negative.

如果我們有負數,則結果將基于左操作數的符號;如果左操作數為正-結果將為正;如果左操作數為負-結果將為負。

Thus, in the result (remainder), the sign of left operand is appended.

因此, 在結果(余數)中,將添加左操作數的符號 。

Understand with the below table:

了解下表:

Left operand Right operand Result Positive Positive PositivePositive Negative PositiveNegative Positive NegativeNegative Negative Negative

Example:

例:

Input:int a = -10;int b = 3;// finding remainderresult = a%b;printf("result = %d\n", result);Output:result = -1

C code to demonstrate example of modulus operator with negative operands

C代碼演示具有負操作數的模運算符的示例

// C program to demonstrate example of // Modules operator (%)#include <stdio.h>int main() {int a = -10;int b = 3;int result;result = a%b;printf("result = %d\n", result);a = 10;b = -3;result = a%b;printf("result = %d\n", result); a = -10;b = -3;result = a%b;printf("result = %d\n", result); return 0; }

Output

輸出量

result = -1 result = 1 result = -1

翻譯自: https://www.includehelp.com/c/modulus-on-negative-numbers.aspx

c語言中負數

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的c语言中负数_C语言中负数的模数的全部內容,希望文章能夠幫你解決所遇到的問題。

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