摘要:
#include<iostream>usingnamespace std;int main(){ int i=4,j=1; do { cout<<"i="<<i<<endl; i--; }while(i!=0);//先执行循环,再判断条件,决定是否继续循环。 do++j; while(j>999);//注意,虽然此时条件为假,但是仍然执行了循环。 cout<<"j="<<j<<endl; return0;}/*do-while循环: 当只有一条循环语句时,用:do 阅读全文
posted @ 2012-06-23 18:57
蚂蚁踩死了大象
阅读(227)
评论(0)
推荐(0)
摘要:
/*主要内容: 1.单个变量的测试表达式。 2.数值求和。 3.循环中使用break的作用。 4.避免创建无限循环。 5.提前终止循环。*/#include<iostream>usingnamespace std;int main(){ int i=4,k=1,sum=0; while(i) { cout<<"old i="<<i; sum+=i; i--; cout<<",new i="<<i<<",sum="<<sum<<endl; } 阅读全文
posted @ 2012-06-23 18:28
蚂蚁踩死了大象
阅读(142)
评论(0)
推荐(0)
摘要:
//使用while循环。#include<iostream>usingnamespace std;int main(){ int i; i=1; while(i<=5)//满足循环条件就进入循环。当不满足循环条件时,循环终止。 { cout<<"Loop number"<<i<<"in the while loop\n"; i++;//改变i的值,使得循环条件情况改变,不会成为死循环。 } return0;}/*while循环:基本结构为: while(expression) { state... 阅读全文
posted @ 2012-06-23 18:15
蚂蚁踩死了大象
阅读(208)
评论(0)
推荐(0)
摘要:
/*1.bool数据类型的使用。 2.bool数据的输入和输出。*/#include<iostream>#include<fstream>#include<iomanip>usingnamespace std;int main(){ bool salty,hard,acidic,good_taste,have_service; double sodium,Ca,Mg,pH; ifstream infile("A.txt"); infile>>sodium>>Ca>>Mg>>pH; salty 阅读全文
posted @ 2012-06-23 16:56
蚂蚁踩死了大象
阅读(524)
评论(0)
推荐(0)
摘要:
/*1.if-else-if控制结构的使用方法。 2.switch语句的使用方法。 3.比较if-else-if控制结构和switch控制结构。*/#include<iostream>usingnamespace std;int miain(){ int option; cout<<"Please type 1,2,or 3\n"; cin>>option; if(option==1) { cout<<"Attend meeting\n"; } elseif(option==2) { cout<< 阅读全文
posted @ 2012-06-23 16:18
蚂蚁踩死了大象
阅读(361)
评论(0)
推荐(0)
摘要:
/*1.逻辑运算符的优先次序。 2.逻辑表达式的求解方法。*/#include<iostream>usingnamespace std;int main(){ int a=4,b=-2,c=0,x; if(a) cout<<"a="<<a<<",!a="<<!a<<endl;//一般非零值都是真,例如c=0,则c为假。输出else. if(b) cout<<"b="<<b<<",!b="<<!b& 阅读全文
posted @ 2012-06-23 15:32
蚂蚁踩死了大象
阅读(144)
评论(0)
推荐(0)

浙公网安备 33010602011771号