#include<bits/stdc++.h> using namespace std; int main() { //while int num = 0; while (num < 10) { cout << "num = " << num << endl; num++; } //猜数字 //rand()%100随机生成1-99的整数 int ans=rand()%100+1; int val; while(1){ cin>>val; if(val>ans){ cout<<"大了"<<endl; } else if(val<ans){ cout<<"小了"<<endl; } else{ cout<<"猜对了"<<endl; break; } } //do...while int num1 = 0; do { cout << num1 << endl; num1++; } while (num1 < 10); //水仙花数 int test=100; while(test<=999) { int a,b,c; a=test%10; b=test/10%10; c=test/100; int d=a*a*a+b*b*b+c*c*c; if(d==test) { cout<<d<<endl; } test++; } //for 循环 for (int i = 0; i < 10; i++) { cout << i << endl; } //敲桌子 for(int i=1;i<=100;i++) { if(i%7==0||i%10==7||i/10==7){ cout<<i<<"敲桌子"<<endl; } } //嵌套循环 for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { cout << "*" << " "; } cout << endl; } //九九乘法表 for(int i=1;i<=9;i++) { for(int j=1;j<=i;j++) { cout<<j<<" "<<"*"<<" "<<i<<" = "<<j*i<<" "; } cout<<endl; } //break语句 一般用于switch和循环(嵌套循环) //continue语句 for (int i = 0; i < 100; i++) { if (i % 2 == 0) { continue; } cout << i << endl; } //goto语句(比较少用) cout << "1" << endl; goto FLAG; cout << "2" << endl; cout << "3" << endl; cout << "4" << endl; FLAG: cout << "5" << endl; return 0; }