#include
int x,y;
cout<<\ cin>>x;
if (x<=0) { //满足条件执行 y=2*x;
cout<<\ //输出结果 }
else { //不满足条件执行 y=x*x;
cout<<\ //输出结果 } }
#include
int a,b,c; int smallest;
cout<<\ b c\ cin>>a>>b>>c;
if (a<=b) //外层条件语句 {
if (a<=c) //内层条件语句 smallest=a; else
smallest=c; } else {
if (b<=c) //内层条件语句 smallest=b; else
smallest=c; }
cout<<\}
#include
int score;
//从键盘上输入分数 cout<<\ cin>>score;
//用带else if的条件语句判断处理 if (score<0 || score>100) {
cout<<\ }
else if (score>=90)
cout<<\our grade is a A.\ else if (score>=80)
cout<<\our grade is a B.\ else if (score>=70)
cout<<\our grade is a C.\ else if (score>=60)
cout<<\our grade is a D.\ else
cout<<\our grade is a E.\}
#include
int n;
cout<<\ cin>>n;
if (n>=0 && n<=100 &&n%2==0) cout<<\ else
cout<<\}
#include
int a,b,Max; //输入数据 cout<<\ cin>>a; cout<<\ cin>>b;
//找出较大值 Max=a>b?a:b;
cout<<\}
#include
int a,b; //输入数据 cout<<\ cin>>a; cout<<\ cin>>b;
//除法判断
if (b!=0 && a%b==0) {
cout<
cout<
#include
//x,y 为操作数,c为运算符 int x,y,z; char c1;
cin>>x>>c1>>y; //c1
//多路选择语句选择不同表达式计算语句
6
switch(c1) {
case '+':cout< case '-':cout< case '*':cout< case '/':cout< case '%':cout< default :cout<<\!\//当不符合上述情 //显示0,0.1,0.2...1.0 for(float x=0;x<=1.0;x=x+0.1) cout< //显示0,0.1,0.2...1.0 for(float x1=0;x1<=1.0+0.1/2;x1=x1+0.1) cout< //计算s=1+2+3...+100 int s=0; 况时执行本子句 } } #include float x=365.5; //声明全局变量 main() { int x=1,y=2; double w=x+y; { double x=1.414,y=1.732,z=3.14; cout<<\ cout<<\ cout<<\ cout<<\ cout<<\ //访问重名的全局变量 } cout<<\ cout<<\ cout<<\ //cout<<\无效 cout<<\ //访问重名的全局变量 } #include //显示1,2,3...10 for(int i=1;i<=10;i++) cout< //显示10,9,8...1 for(int j=10;j>=1;j--) cout< //显示1,3,5...9 for(int k=1;k<=10;k=k+2) cout< //显示ABC...Z for(char c='A';c<='Z';c++) cout< for(int n=1;n<=100;n++) s=s+n; cout<<\} #include //计算s=1+2+3...+100 int s=0,n=1; while(n<=100) { s=s+n; n++; } cout<<\ //累加键盘输入的数据 double x,sum=0.0; cout<<\ cin>>x; while(x!=0) { sum+=x; cout<<\ cin>>x; } cout<<\} #include //计算s=1+2+3...+100 int s=0,n=0; do { n++; s+=n; }while(n<100); cout<<\ //累加键盘输入的数据 double x,sum=0.0; do { cout<<\ cin>>x; sum+=x; } while(x!=0); cout<<\} #include 7 main() { //计算和打印打印乘法九九表 for (int i=1;i<=9;i++) { cout< for (int j=1;j<=9;j++) cout<<'\\t'< #include int x,sum=0; //定义标号L1 L1: cout<<\ cin>>x; if (x==-1) goto L2; //无条件转移语句,转到L2语句处 else sum+=x; goto L1; //无条件转移语句,转到L1语句处 //定义标号L2 L2: cout<<\} #include //累加键盘输入的数据 double x,sum=0.0; while(1) { cout<<\ cin>>x; if (x<=0) break; sum+=x; } cout<<\} #include int i; for (i=1;i<=20;i++) { if (i%3==0) //能被 3 整除的整数,返回进行下次循环 continue; cout< cout< #include //声明数组和变量 int a[5],i,sum; 8 double avg; //从键盘上循环为数组赋值 for (i=0;i<5;i++) { cout<<\ cin>>a[i]; } //直接显示数组元素 cout< //利用for循环显示数组各元素的值 for (i=0;i<5;i++) cout< //计算数组元素之和,并显示计算结果 sum=a[0]+a[1]+a[2]+a[3]+a[4]; cout<<\ //利用循环计算数组的累加和 for (sum=0,i=0;i<5;i++) sum+=a[i]; //显示累加和及平均值 cout<<\ avg=sum/5.0; cout<<\} #include int i,max,index,a[5]; //从键盘上为数组赋值 for (i=0;i<=4;i++) { cout<<\ cin>>a[i]; } // 利用循环遍历数组,找出最大值的元素及其下标 max=a[0]; for (i=0;i<=4;i++) { if (max max=a[i]; index=i; } } cout<<\ index=\} #include //声明变量 int i,j; float t,a[size]; //从键盘上为数组赋值 for (i=0;i cout<<\ cin>>a[i]; } //对数组按从小到大顺序排序 for (i=0;i for (j=i+1;j t=a[i]; a[i]=a[j]; a[j]=t; } //显示排序结果 for (i=0;i //输入要查找的数据 int value; int found; //找到为1,否则为0 int low,high,mid; for (i=1;i<=3;i++) { cout<<\ cin>>value; //二分法查找数组a found=0; low=0; high=size-1; while(low<=high) { mid=(high+low)/2; if (a[mid]==value) { found=1; break; } if (a[mid] high=mid-1; } if (found) cout<<\valu found at:a[\ else cout<<\ } } #include 9 float t,a[5]; //从键盘上为数组赋值 for (i=0;i<=4;i++) { cout<<\ cin>>a[i]; } //对数组按从大到小顺序排序 for (i=0;i<=3;i++) for (j=i+1;j<=4;j++) if (a[i]<=a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; } //显示排序结果 for (i=0;i<=4;i++) cout< #include //声明二维数组及变量 int a[2][3],i,j; //从键盘上为数组a赋值 for (i=0;i<2;i++) for (j=0;j<3;j++) { cout<<\ cin>>a[i][j]; } //显示数组a for (i=0;i<2;i++) { for (j=0;j<3;j++) { cout< cout< //找出该数组的最大元素及其下标 int h,l,Max=a[0][0]; for (i=0;i<2;i++) { for (j=0;j<3;j++) {