欢迎来到天天文库
浏览记录
ID:41393831
大小:55.97 KB
页数:15页
时间:2019-08-24
《C语言入门知识习题演练》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、C语言入门知识习题演练CyclicstructureWhile(condition){body}//1.output****************;#includeInt,main(){Inti=0;Wh订e(i<10){Printf(*);I++;//i二i+1;}Printf(〃〃);}2.for(initialcondition,cyclecondition,cyclicincrement)//loop//firstperformsinitializationconditions/executioncycleconditions一一>body
2、circulationandincreasecirculationconditions-->-->-->loop一circularincrementFor:****************#includeInt,main(){Theuseoffor//outputcycleFor(inti二0;i<10;i++){Printf(*);}Printf(〃〃);}1.printallthenumbersthat0--1000canbedivisibleby3and7withtheforloopandcalculatethenumber#include〈s
3、tdio.h>Inti=0;Intcount二0;//thisisacountervariableFor((i<=100;i++){If(i%5=0){Printf(〃%d〃,I);Count++;//eachincrement1}}Printf(〃atotalof%dnumberscanbedivisibleby5by〃,"count");}#include〈stdio.h>Int,main(){Calculateall3digitsin//thenumberofdaffodilsInti二100:IntShi二0;IntBai二0;For((i<1000;i+
4、+){Ge二i%10;Shi二i/10%10;Bai二i/100:If(ge*ge*ge+shi*shi*shi+bai*bai*bai二二I){Printf(〃%disnarcissusnumberrT,I);}}}Thedeadloopinthe4.forloop#includeInt,main(){Inti二0;(for;i<10;i++){//loopconditionisempty(i<10)orifthecircularincrementisempty(i++),thecycleofdeathPrintf(〃%d〃,I);5.do{//
5、loop}while(condition);Explanation:thewhileloopisthefirsttodeterminetheloopcondition,andtheconditionisfulfilled・Thewhileloopexecutesatleast0times・Do.・Whilefirstexecutestheafterjudgmentcondition,anddo.・Whileperformsatleast1times・[Focus]theforloopisalreadyawareofthenumberofcycles・Summing:#in
6、clude〈stdio.h>Int,main(){Do{Sum二sum+i;I++;}while(i〈二1000);Printf(〃%d〃,sum);}5.monkeyseatpeachesproblem#includeInt,main(){Intt=9;//tindicatesthefirstfewdaysIntx二1;//xindicatesthenumberofpeachesFor((t>=l;t--){X二(x+1)*2;Printf(〃%dpeachonday%d",t,X);5.nestedloops:int,i=0,j二0;(for
7、;i<10;i++){//outerloop(for;j<10;j++){//innerloopEmphasis:theouterloopexecutesonce,andtheinnerloopexecutesacircle*OnetwothreefourfivesixseveneightnineOnetwothreefourfivesixseveneightnineOnetwothreefourfivesixseveneightnineOnetwothreefourfivesixseveneightnineOnetwothr
此文档下载收益归作者所有