C 语言实例 - 循环区间范围内的奇数/偶数
C 语言教程
· 2019-02-20 16:28:17
循环输出区间范围内的奇数/偶数可以通过除于 2 的余数来判断。
以下实例通过循环输出指定区间范围的偶数。
实例
#include <stdio.h>
int main() {
int i;
for(i = 1; i <= 10; i++) {
if(i%2 == 0)
printf(" %2d\n", i);
}
return 0;
}
运行结果:
2 4 6 8 10
以下实例通过循环输出指定区间范围的奇数。
实例
#include <stdio.h>
int main() {
int i;
for(i = 1; i <= 10; i++) {
if(i%2 != 0)
printf("%d\n", i);
}
return 0;
}
运行结果:
1 3 5 7 9
点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html
Designing Data-Intensive Applications
Martin Kleppmann / O'Reilly Media / 2017-4-2 / USD 44.99
Data is at the center of many challenges in system design today. Difficult issues need to be figured out, such as scalability, consistency, reliability, efficiency, and maintainability. In addition, w......一起来看看 《Designing Data-Intensive Applications》 这本书的介绍吧!