C Programming 判断奇偶数与循环输入实现

版权声明:转载请附上博客地址 https://blog.csdn.net/weixin_38134491/article/details/84678031

本节主要考察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;
}





猜你喜欢

转载自blog.csdn.net/weixin_38134491/article/details/84678031