C语言-while循环,continue/break,getchar()/putchar()

while循环中的continue/break

复制代码
#include<stdio.h>

int main() {

	//while循环中 continue  和 break 的不同
	//break是用于永久的终止循环
	//continue 跳过本次循环后面的代码,直接去判断部分,进行下一次的循环的判断

	int i = 1;
	//while (i <= 10) {
	//	if (i == 5)
	//		break;
	//	printf("%d ", i);
	//	i++;
	//}
	//while (i <= 10) {
	//	if (i == 5)
	//		continue;
	//	printf("%d ", i);
	//	i++;
	//}
	while (i <= 10) {
		i++;
		if (i == 5)
			continue;
		printf("%d ", i);
	}
	return 0;
}

getchar()/putchar()

复制代码
#include<stdio.h>
int main() {
	////EOF ;//end of file
	//int ch=getchar();//输入获得一个字符
	////下面的两种打印方式相同
	//printf("%c\n", ch);//1
	//putchar(ch);//2

	//int ch = 0;
	//while ((ch=getchar())!=EOF) {
	//	putchar(ch);
	//}

	//举一个应用例子
	//假设密码是一个字符串
	//char password[20] = { 0 };
	//printf("请输入密码:>");
	//scanf("%s", password);
	////
	////getchar();//读走了\n

	//int ch = 0;
	//while ((ch=getchar())!='\n') {
	//	;
	//}

	//printf("请确认密码(Y/N):>");
	//int ret = getchar();
	//if ('Y'==ret)
	//{
	//	printf("Yes\n");
	//}
	//else {
	//	printf("No\n");

	//}

	char ch = '\0';
	while ((ch = getchar()) != EOF) {
		if (ch<'0'||ch>'9')
			continue;
			putchar(ch);//只打印数字字符,跳过其他字符

	}
	return 0;
}
相关推荐
怕浪猫6 小时前
RAG 面试 6 连问,从原理到优化全部覆盖
python·算法·面试
yyy(十一月限定版)6 小时前
224redfg
c语言
无线通信科研笔记6 小时前
IEEE TVT 2026 论文精读与完整复现|相位误差如何重塑近场 RIS 的幅相响应
论文阅读·人工智能·python·算法·论文笔记
daidaidaiyu7 小时前
ThingsBoard 集群的核心逻辑源码分析
java
mmmmath_37 小时前
二叉树の递归遍历
算法
All for pursuit.8 小时前
【位运算-1】338.比特位计数
数据结构·c++·算法·leetcode
我可能是个假开发8 小时前
FTP Unicode 文件名导致 `550` 的问题分析与解决方案
java·开发语言·spring
caoerzhong8 小时前
中小企业上 WMS 该先上哪几块:JeeWMS 开源 Java 仓库管理系统的分批上线清单
java·python·开源
小师兄吃牛肉8 小时前
C语言中的nullptr有必要吗
c语言·c++·算法
【JAVA】玩家9 小时前
Spring核心原理全解析:从零到生产实战
java·后端·spring