打印*
#include<iostream> using namespace std; #include<string.h> int main(){ for(int i=1;i<=9;i++){ for(int j=1;j<i;j++){ cout<<j<<"*"<<i<<"="<<j*i<<" "; } cout<<endl; } system("pause"); }
continue用法
#include<iostream> using namespace std; #include<string.h> int main(){ for(int i=0;i<=100;i++){ if(i%2==0){ continue; } cout<<i<<endl; } system("pause"); }
排序
#include<iostream> using namespace std; int main(){ int arr[9]={4,2,8,0,5,7,1,3,9}; cout<<"排序前:"<<endl; for (int i=0;i<9;i++){ cout<<arr[i]<<" "; } cout<<endl; for(int i=0;i<9-1;i++){ for(int j=0;j<9-i-1;j++){ if(arr[j]>arr[j+1]){ int temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; } } } for (int i=0;i<9;i++){ cout<<arr[i]<<" "; } system("pause"); }
猜数字
#include<iostream> using namespace std; #include<ctime> int main(){ srand((unsigned int)time(NULL)); int num=rand()%100+1; int val=0; while(1){ cin>>val; if(val>num)cout<<"猜测过大"<<endl; else if(val<num)cout<<"猜测过小"<<endl; else{ cout<<"恭喜您猜对了"<<endl; break; } } system("pause"); }
goto用法
#include<iostream> using namespace std; int main(){ cout<<"1、xxxx"<<endl; cout<<"2、xxxx"<<endl; goto FLAG; cout<<"3、xxxx"<<endl; cout<<"4、xxxx"<<endl; FLAG: cout<<"5、xxxx"<<endl; system("pause"); }