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 = -1C 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 NegativeExample:
例:
Input:int a = -10;int b = 3;// finding remainderresult = a%b;printf("result = %d\n", result);Output:result = -1C 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语言中负数的模数的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 颐和园不满七岁要买票吗
- 下一篇: 颐和园六十岁以上的人收费吗
