C控制语句--分支和跳转
来源:互联网 发布:177pic info新域名 编辑:程序博客网 时间:2024/06/01 19:35
/*C控制语句--分支和跳转*//*关键字 if else switch continue break case default goto 运算符:&&(且) ||(或) ?:(三元运算符) 函数 getchar() putchar() 怎样使用if和if else 语句以及如何嵌套使用它们。 使用逻辑运算符将关系表达式组合为更加复杂的判断表达式。 C的条件运算符。 swich语句。 break、continue、和goto跳转。 使用C的字符I/O函数 getchar()和putchar()。 由ctype.h头文件提供的字符分析函数系列。*///求出温度低于零度的天数的百分率#include<stdio.h>int main(void){ const int FREEZING=0; //定义一个整形常量 float temperature; //定义一个浮点型变量 int cold_days=0; int all_days=0; printf("Enter the list of daily low temperatures.\n"); printf("Use Celsius, and enter q to quit.\n"); while(scanf("%f",&temperature)==1) //判断输入的格式 { all_days++; //格式正确天数加1 if(temperature<FREEZING) //如果温度小于0 { cold_days++; //小于零度的天数加1 } } if(all_days!=0) //天数不等于0输出 { printf("%d days total; %.lf%% were below freezing.\n",all_days,100.0*(float)cold_days/all_days); } if(all_days==0)//天数等于0输出 { printf("No data entered!\n"); } system("pause"); //按任意键继续...}
/*--统计字符、单词和行*/#include <stdio.h>#include <ctype.h> //为isspace()提供函数原型#include <iso646.h> #include<stdbool.h>#define STOP '|'int main(void){ char c; //读入字符 char prev; //前一个读入字符 long n_chars=0; //字符数 int n_lines=0; int n_words=0; int p_lines=0; bool inword=false; printf("输入一段文本用|分开\n"); prev='\n'; while(c=getchar()!=STOP) { n_chars++; if(c=='\n') { n_lines++; } if(!isspace(c)&&!inword) { inword=true; n_words++; } if(isspance(c)&&inword) { inword=false; } prev=c; } if(prev!='\n') { p_lines=1; } pirntf("characters=%1d,words=%d,lines=%d,",n_chars,n_words,n_lines); printf("partial lines=%d\n",p_lines); system("pause");}
/*--三元运算符*/#include <stdio.h>int main(void){ int n=0; int num; printf("请输入一个整数:\n"); scanf("%d",&n); num=(n<0)?-n:n; //如果 n<0 那么num=-n 否则num=n; printf("绝对值为:%d",num); system("pause");}
continue break goto swich略。
0 0
- C控制语句:分支和跳转
- C控制语句--分支和跳转
- C控制语句:分支和跳转
- c控制语句:分支和跳转
- C语言基础:C控制语句:分支和跳转
- C语言学习_007_C控制语句:分支和跳转
- 第七章 C控制语句:分支和跳转
- 第七章 C控制语句:分支和跳转
- C控制语句:分支和跳转(1)
- c控制语句:分支和跳转(2)
- C控制语句之分支和跳转(一)
- C控制语句之分支和跳转(二)
- C控制语句:分支与跳转
- C primer plus第7章(C控制语句:分支和跳转)习题
- 第七章 C控制语句:分支和跳转-C primer plus
- C primer plus 第七章 C控制语句-分支和跳转 编程练习个人答案
- C Primer Plus 第7章 C控制语句:分支和跳转 编程练习
- 黑马程序员——C语言学习笔记02 控制语句:分支、跳转、循环和函数一些需要注意的问题
- C--运算符,表达式和语句实例
- 总结Cocos2d-x中Layer的使用(CCLayerColor、CCLayerGradient、CCLayerMultplex)
- C--控制语句循环例子
- svn: Authorization failed
- 汇编基础:二进制和十六进制
- C控制语句--分支和跳转
- ASP.NET学习笔记--自己写的Login.aspx
- ASP.NET学习笔记2--自己写代码绑定Gridview
- C---指针
- Jquery--仿制360右下角弹出窗口
- C--指针数组
- C---通过指针访问数组
- C---数组名作函数参数
- C_数据结构