zoukankan      html  css  js  c++  java
  • 一些数学运算

    %

    x%y语义上:如果x和y都是正整数,结果是x除以y的余数

    这个运算结果的取值范围是[0, x-1]
    

    但值得注意的是

    // Program to illustrate the
    // working of the modulo operator
    
    #include <stdio.h>
    
    int main(void)
    {
    
    	// To store two integer values
    	int x, y;
    
    	// To store the result of
    	// the modulo expression
    	int result;
    
    	x = -3;
    	y = 4;
    	result = x % y;
    	printf("%d", result);
    
    	x = 4;
    	y = -2;
    	result = x % y;
    	printf("
    %d", result);
    
    	x = -3;
    	y = -4;
    	result = x % y;
    	printf("
    %d", result);
    
    	return 0;
    }
    
    -3
    0
    -3
    

    参考

    如果看过了参考,就知道,上面这个示例代码所使用的编译器,对于符号模问题的实现是使余数与被除数同符号

    此外,参考中的这个部分讲述得非常本质


    几乎所有的计算系统中,a 除 n 得到商 q 和余数 r 均满足以下式子:

    (egin{aligned} q & in mathbb{Z} \ a &=n q+r \ |r| &<|n| end{aligned})up

  • 相关阅读:
    Django(二)
    Django(一)
    MYSQL理论知识汇总
    默认参数
    深浅拷贝和赋值关系
    bootstrap常用知识
    jQuery常用功能代码
    java集合框架知识总结
    Mysql数据库SQL语句整理
    基于IO流的模拟下载文件的操作
  • 原文地址:https://www.cnblogs.com/ijpq/p/15405107.html
Copyright © 2011-2022 走看看