2.4重学C++之【for循环、案例】
#include<iostream>
using namespace std;
int main(){
//2 循环结构
//2-3 for(起始表达式0;条件表达式1;末尾循环体2){循环语句3}
//起始表达式仅执行1次;执行顺序:0 123 123 123 ...
for(int i=0; i<10; i++){
cout << i << endl;
}
cout << "\n" << endl;
int a=0;
for(; a<10; a++){
cout << a << endl;
}
cout << "\n" << endl;
int b=0;
for(; ; b++){
if(b >= 10){
break;
}
cout << b << endl;
}
cout << "\n" << endl;
int c=0;
for(; ; ){
if(c >= 10){
break;
}
cout << c << endl;
c++;
}
cout << "\n" << endl;
//案例-敲7:1~100中含有7或7的倍数
//7的倍数(7 14 21 28 ,,)%7=0
//个位含7(7 17 27 37 ,,)%10=7
//十位含7(70 71 72 73 ,,)/10=7
for (int i=1; i<=100; i++){
if ((i%7==0) || (i%10==7) || (i/10==7)){
cout << "敲。。。" << endl;
}else{
cout << i << endl;
}
}
return 0;
}