読み込んだ整数値を0までカウントダウン (while文)

明解C言語 入門編 > 4. プログラムの流れの繰り返し >

読み込んだ整数値を0までカウントダウン (while文)

C


#include <stdio.h>
int main(int argc, char* argv[])
{
int no;

printf("正の整数を入力してください:");
scanf("%d", &no);

while (no >= 0)
{
printf("%d\n", no--);
}

return 0;
}

実行結果

T:\>lesson027\project1.exe
正の整数を入力してください:11
11
10
9
8
7
6
5
4
3
2
1
0

T:\>lesson027\project1.exe
正の整数を入力してください:0
0

T:\>lesson027\project1.exe
正の整数を入力してください:-5