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

int main(int argc, char *argv[]) {

//條件判斷式 if else, while, ...

int input;

printf("請輸入一個整數:");
scanf("%i", &input);



// input 除以2,餘數等於0,就是偶數
// 當然啦,如果input初以2於1的話,就是奇數

if(input%2==0){
printf("您輸入的值%i是偶數", input);
}else{
printf("您輸入的值%i是奇數", input);
}



//也可以寫成這樣,因為 if(input%2) = if(1)

if(input%2){
printf("您輸入的值%i是奇數", input);
}else{
printf("您輸入的值%i是偶數", input);
}



//也可以寫成這樣,用!作反向
if(!(input%2)){
printf("您輸入的值%i是偶數", input);
}else{
printf("您輸入的值%i是奇數", input);
}

return 0;

}

arrow
arrow
    全站熱搜

    kenohya 發表在 痞客邦 留言(0) 人氣()