分支结构例题.doc

上传人:s9****2 文档编号:559858799 上传时间:2023-08-13 格式:DOC 页数:3 大小:37.51KB
返回 下载 相关 举报
分支结构例题.doc_第1页
第1页 / 共3页
分支结构例题.doc_第2页
第2页 / 共3页
分支结构例题.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《分支结构例题.doc》由会员分享,可在线阅读,更多相关《分支结构例题.doc(3页珍藏版)》请在金锄头文库上搜索。

1、【源程序1】大小写转换示例。#include main() char c1,c2; scanf(%c,&c1); printf(%c,%dn,c1,c1); c2=c1+32; printf(%c,%dn,c2,c2); getch();【源程序2】求三角形的面积。#include main() float a,b,c,s,area; scanf(%f,%f,%f,&a,&b,&c); s=1.0/2*(a+b+c); area=sqrt(s*(s-a)*(s-b)*(s-c); printf(%fn,area); getch(); 3,4,5修改后#include main() float

2、a,b,c,s,area; scanf(%f%f%f,&a,&b,&c); s=1.0/2*(a+b+c); area=sqrt(s*(s-a)*(s-b)*(s-c); printf(%fn,area); getch(); 3 4 5再修改#include main()float a,b,c,s,area; scanf(%f%f%f,&a,&b,&c); if(a+bc&b+ca&a+cb) s=1.0/2*(a+b+c); area=sqrt(s*(s-a)*(s-b)*(s-c) ; printf(area=%6.2fn,area);else printf(It is not a tri

3、lateral.); getch();【源程序3】逻辑运算符短路求值示例。#includemain() int a=1,b=2,c=3,d=4,m=1,n=1; int x; x=(m=ab)&(n=cd); printf(x=%dn3,x); printf(m=%d,n=%dn,m,n); getch(); 修改后#includemain() int a=1,b=2,c=3,d=4,m=1,n=1; int x; x=(m=ab)&(n=cd); printf(x=%dn,x); printf(m=%d,n=%dn,m,n); getch(); 【源程序4】if语句语法1结构用法示例。#in

4、clude main() int a,b; scanf (%d%d,&a,&b); if(ab) printf(%dn,a); else printf (%dn,b); getch(); 【源程序5】if语句语法2结构用法示例。#includemain() char ch; scanf(%c,&ch); if(ch=a&ch=z) ch-=a-A; printf(%cn,ch); getch(); 【源程序6】if语句嵌套结构用法示例。#include main()char c; scanf(%c,&c); if (c=0&c=A&c=a&c=z) printf (This is a small letter.n); else printf (This is an other charater.n); getch();【源程序7】else和if的匹配问题示例。#includemain( ) float x,y; scanf(%f,&x); if (x0) y=-1; else if (x=0) y=0; else y=1; printf(x=%f,y=%2.0fn,x,y); getch();

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号