C语言编程学习课件 (25).pdf

上传人:刘静 文档编号:57975388 上传时间:2022-11-06 格式:PDF 页数:9 大小:1.69MB
返回 下载 相关 举报
C语言编程学习课件 (25).pdf_第1页
第1页 / 共9页
C语言编程学习课件 (25).pdf_第2页
第2页 / 共9页
点击查看更多>>
资源描述

《C语言编程学习课件 (25).pdf》由会员分享,可在线阅读,更多相关《C语言编程学习课件 (25).pdf(9页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、Programming In CProgramming In C Flow control statement When solving practical problems,we often need to When solving practical problems,we often need to exit a loop early,or we want to skip some exit a loop early,or we want to skip some statements in a loop,so we need some special ways statements i

2、n a loop,so we need some special ways to control program flow.to control program flow.break statement continue statement break statement Syntax of break statement:break;Function of break statement:Exit from a switch or a loop.Pay attention to:(1)The break statement can only be used in switch stateme

3、nt or loop statements.(2)The break statement can only be used in switch statement or loop statements.continue statement Syntax of continue statement:continue;Function of break statement:The continue statement only works in loops.It is used to interrupt the current execution of the loop body,that is

4、skipping statements that have not yet been executed in the loop body,and start the next repetition immediately.(1)The continue statement is usually used with the if statement.It can only end the current repetition but cannot terminate the entire loop.(2)If the continue statement is written in a for

5、loop,the increment in the for statement is still executed.Pay attention to:break#include main()int i,n;for(i=1;i=5;i+)printf(Please enter n:);scanf(%d,&n);if(n 0)break;printf(n=%dn,n);printf(Program is over!n);n-10 Running result:Please enter n:10 n=10 Please enter n:6 n=6 Please enter n:-10 Program

6、 is over!continue#include main()int i,n;for(i=1;i=5;i+)printf(Please enter n:);scanf(%d,&n);if(n 0)continue;printf(n=%dn,n);printf(Program is over!n);n 30 Running result:Please enter n:10 n=10 Please enter n:-10 Please enter n:20 n=20 Please enter n:-20 Please enter n:30 n=30 Program is over!Questio

7、n 1 Enter a positive integer m to check whether it is a prime number.The prime numbers are positive integers that can only be divided by 1 and itself.1 is not a prime number while 2 is.#include#includestdio.hstdio.h#include#includemath.hmath.h voidvoid main()main()intint i,m,n;i,m,n;scanf(%d,&m);sca

8、nf(%d,&m);n=(int)sqrt(m);n=(int)sqrt(m);forfor(i=2;i(i=2;in)printf(%d is a prime number!(in)printf(%d is a prime number!n,m);n,m);elseelse printf(%d is not a prime number!printf(%d is not a prime number!n,m);n,m);Running result:Question 2 Output a number in the range of 11000 that can be divided by 3,5,7.#include void main()int n;for(n=1;n=1000;n+)if(n%3!=0)continue;if(n%5!=0)continue;if(n%7!=0)continue;printf(%d ,n);printf(n);Running result:Programming In CProgramming In C

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com