C language code for taking the remainder
The remainder operation is expressed in the C language using the %
operator. When two integers are divided, the %
operator returns the remainder after the division operation.
<code class="c">#include <stdio.h> int main() { int num1, num2, remainder; printf("输入第一个数字:"); scanf("%d", &num1); printf("输入第二个数字:"); scanf("%d", &num2); remainder = num1 % num2; printf("两数相除的余数是:%d\n", remainder); return 0; }</code>
Code description:
<stdio.h>
. num1
, num2
and remainder
, which are used to store two dividends and remainder respectively. printf
function to prompt the user to enter two numbers. scanf
function to read user input and store it in the num1
and num2
variables. num1
divided by num2
using the %
operator and store it in the remainder
variable . printf
function to print the remainder of the division operation. The above is the detailed content of How to write the C language code to get the remainder. For more information, please follow other related articles on the PHP Chinese website!