2009年12月7日 星期一

餘數運算子:%

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x,x2;
    printf("輸入數字:");
    scanf("%d",&x);
    x2=x%5;
    printf("%d除5的餘數為:%d",x,x2);

    return 0;
}


/*

結果:

輸入數字:11
11除5的餘數為:1

*/


補充 :
0%5 → 0
1%5 → 1
2%5 → 2
3%5 → 3
4%5 → 4
5%5 → 0
6%5 → 1
7%5 → 2
.............................

沒有留言:

張貼留言