一if语句
1.格式:if(表达式)
语句体;
2.常用运算符:>、>=、<、<=、==、!=
3.实例:
#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a%2!=0)
printf("odd");
if(a%2==0)
printf("even");
return 0;
}
二if else语句
1.格式:
if(表达式)
语句体1;
else
语句体2;
修改上式代码
#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a%2!=0)
printf("odd");
else
printf("even");
return 0;
}
三getchar()、putchar()函数
字符专用输入输出函数
1getchar()输入函数:<字符变量>=getchar()
char ch;
ch=getchar();特殊1无参数且只输出1个字符
2若有多个字符,只输出第一个
2putchar()输出函数:有参数putchar(c)
四逻辑运算符
把多个关系表达式组合起来会很有用
&& 与
|| 或
! 非
#include<stdio.h>
#define PERIOD '.'
int main()
{
char ch;
int charcount=0;
while((ch=getchar())!=PERIOD)
{
if(ch!='"'&&ch!='\'')
charcount++;
}
printf("There are %d non-quote characters.\n",charcount);
return 0;
}
五备选拼写:iso646.h头文件
1and代替&&
or代替||
not代替!
六循环辅助
1continue语句:终止本次循环,直接进入下一个循环。
2break语句:终止循环,如果执行break语句,则直接终止循环。