/*
int main()
{
int a = 0;
int b = 2;
if (a == 1)
if (b == 2)
printf("hehe");
printf("haha"); //打印出haha,a==1不满足不执行if(b==2)会直接执行打印haha
return 0;
}
*/
/*
int main()
{
int a = 0;
int b = 2;
if (a == 1)
if (b == 2)
printf("hehe\n");
else
printf("haha\n");//else与最近未匹配的if相对,与缩进无关
return 0;
}
*/
/*
//练习1:判断一个数是否为奇数
int main()
{
int num = 0;
int num1 = 0;
scanf("%d",&num);
num1 = num % 2;
if (num1 == 1)
{
printf("为奇数\n");
}
else
{
printf("为偶数\n");
}
return 0;
}
*/
/*
//练习2:输出1-100之间的奇数
int main()
{
int n = 0;
while(n <= 100)
{
if (n % 2 == 1)//取余数
{
printf("%d\n", n);
}
n++;
}
return 0;
}
*/
/*
int main()
{
int day = 0;
scanf("%d", &day);
switch (day)//switch表达式必须是整形int
{
case 1://case后必须是整形常量表达式,即为1,非1.0,可以使1+0
printf("星期1\n"); break;
case 2:
printf("星期2\n"); break;
case 3:
printf("星期3\n"); break;
case 4:
printf("星期4\n"); break;
case 5:
printf("星期5\n"); break;
case 6:
printf("星期6\n"); break;
case 7:
printf("星期7\n"); break;
}
return 0;
}
*/
/*
int main()
{
int day = 0;
scanf("%d", &day);
switch (day)//switch表达式必须是整形int
{
case 1: //case后不一定需要加break
case 2:
case 3:
case 4:
case 5:
printf("工作日\n"); break;
case 6:
case 7:
printf("休息日\n"); break;
default://default位置可随意,但一般放后边
printf("输入错误\n"); break;//防止输入数值大于7导致没有结果
}
return 0;
}
*/
/*
int main()
{
int n = 1;
int m = 2;
switch (n)//↓
{
case 1:m++;//m=3 n=1 无break继续执行case2
case 2:n++;//m=3 n=2 无break继续执行case3
case 3:
switch (n)//n=2执行case2
{
case 1: n++;
case 2:m++; n++; break;//m=4 n=3 有break跳出switch
}
case 4:m++; break;//m=5 n=3
default:break;
}
printf("m= %d,n= %d\n",m,n);
return 0;
}
*/
/*
int main()
{
int i = 1;
while (i <= 10)
{
if (i == 5)
break;
printf("%d ",i);
i++;
}//输出1 2 3 4
return 0;
}
*/
/*
int main()
{
int i = 1;
while (i <= 10)
{
if (i == 5)
continue;//跳过本次循环直接进入while重新判断,并不向下进行
printf("%d ", i);
i++;
}//输出1 2 3 4然后进入死循环
return 0;
}
*/
/*
int main()
{
int i = 0 ;
while (i <= 10)
{
i++;
if (i == 5)
continue;//跳过本次循环直接进入while重新判断,并不向下进行
printf("%d ", i);
}//输出1 2 3 4 6 7 8 9 10
return 0;
}
*/
int main()
{//putchar输出字符与printf(%c)作用一样
int ch = 0;
//getchar遇到ctrl+z就会停止
//EOF--> end of file --> =-1
while ((ch = getchar()) != EOF)//getchar接受键盘输入字符,
{
putchar(ch);
}
return 0;
}
标签:case,return,int,代码,C语言,break,printf,main From: https://blog.51cto.com/u_15929197/6052261