Home  >  Article  >  Backend Development  >  What is the remainder symbol in C language?

What is the remainder symbol in C language?

coldplay.xixi
coldplay.xixiOriginal
2020-08-28 11:07:4964181browse

The remainder symbol in C language is [%], and the remainder symbol depends on the dividend, that is, if the dividend is a positive number, the remainder is a positive number; if the dividend is a negative number, the remainder is a negative number, and the syntax is [dividend% divisor] =remainder].

What is the remainder symbol in C language?

In C language, the remainder operation is also called the modulo operation. The sign of the remainder depends on the dividend, that is, if the dividend is a positive number, the remainder is positive. number; if the dividend is a negative number, the remainder will be a negative number.

Remainder operation syntax

Remainder operator:%

被除数%除数=余数

Remainder operation example:

#include <stdio.h>
int main(void)
{
    printf("%d\n", 8%5);
    printf("%d\n", 8%-5);
    printf("%d\n", -8%5);
    printf(" %d\n", -8%-5);
    return 0;
}

The above program output:

3
3
-3
-3

Related learning recommendations: C video tutorial

The above is the detailed content of What is the remainder symbol in C language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn