C言語で余りを求める場合は、%を使用します。
以下にサンプルコードを記します。
以下にintの変数を割り算し、余りを求めるサンプルコードと実行例を記します。
C言語で余りを求める場合は、%を使用します。
余り = 値 % 値
&ref(): File not found: "mod.c" at page "数値/余りを求める・%"; (改行コードLF)
#include <stdio.h> int main(void) { int a = 10; int b = 3; int c = 2; printf("%d / %d = %d...%d\n", a, b, a / b, a % b); printf("%d / %d = %d...%d\n", a, c, a / c, a % c); return 0; }
以下にサンプルコードをコンパイルし、実行した時の結果を記します。
$ gcc mod.c -o mod $ ./mod 10 / 3 = 3...1 10 / 2 = 5...0
以上、C言語で割り算の余りを求める方法でした。
c-btm.html is not found or not readable.