C Programming 判斷奇偶數與迴圈輸入實現
阿新 • • 發佈:2018-12-04
本節主要考察C語言基本語法中兩個知識點
- 怎麼判斷奇數偶數問題
- 以及怎麼實現重複輸入的問題
Problem 1
Write a program that reads an integer and determines and prints whether it is odd or even.
Hint:
- Use the reminder operator.
- An even number is a multiple of two
- Any multiple of two leaves a remainder of zero when divided by 2
Consle result as follows:
Input an integer : 78
78 is an even integer
Input an integer :79
79 is an odd integer
#include<stdio.h> #include<stdlib.h> int main(void) { while (1) { int n = 1; printf("Input an integer:"); scanf_s("%d", &n); if (n % 2 == 0) { printf("%d is an even integer\n", n); } else { printf("%d is an odd integer\n", n); } } system("pause"); return 0; }