cout<<"b="<
cout<<"c="<}
cin>>dx;
cout<<"dy=";
cin>>dy;
cout<cout<cout<cout<//cout<//测试float和double类型数据的有效位
fx=10.0;fy=6.0;
floatfz=fx/fy;
dx=10.0;dy=6.0;
doubledz=dx/dy;
cout<<"fz=";
cout<cout<<"dz=";
cout<//float型溢出
floatx=3.5e14;
cout<<"x="<cout<<"x*x="<cout<<"x*x*x="<}
#include
main()
{
//x,y为操作数,c为运算符
intx,y,z;
charc1;
cin>>x>>c1>>y;//c1
//多路选择语句选择不同表达式计算语句
switch(c1){
case'+':
cout<break;
case'-':
cout<break;
case'*':
cout<break;
case'/':
cout<break;
case'%':
cout<break;
default:
cout<<"Wrong!
"<}
}
#include
floatx=365.5;//声明全局变量
main(){
intx=1,y=2;
doublew=x+y;
{
doublex=1.414,y=1.732,z=3.14;
cout<<"inner:
x="<cout<<"inner:
y="<cout<<"inner:
z="<cout<<"outer:
w="<cout<<":
:
x="<<:
:
x<}
cout<<"outer:
x="<cout<<"outer:
y="<cout<<"outer:
w="<//cout<<"inner:
z="<cout<<":
:
x="<<:
:
x<}
#include
main(){
//显示1,2,3...10
for(inti=1;i<=10;i++)
cout<
cout<//显示10,9,8...1
for(intj=10;j>=1;j--)
cout<cout<//显示1,3,5...9
for(intk=1;k<=10;k=k+2)
cout<cout<//显示ABC...Z
for(charc='A';c<='Z';c++)
cout<cout<//显示0,0.1,0.2...1.0
for(floatx=0;x<=1.0;x=x+0.1)
cout<cout<//显示0,0.1,0.2...1.0
for(floatx1=0;x1<=1.0+0.1/2;x1=x1+0.1)
cout<cout<//计算s=1+2+3...+100
ints=0;
for(intn=1;n<=100;n++)
s=s+n;
cout<<"s="<
}
#include
main()
{
//计算s=1+2+3...+100
ints=0,n=1;
while(n<=100){
s=s+n;
n++;
}
cout<<"s="<
//累加键盘输入的数据
doublex,sum=0.0;
cout<<"x=";
cin>>x;
while(x!
=0){
sum+=x;
cout<<"x=";
cin>>x;
}
cout<<"sum="<}
#include
main()
{
//计算s=1+2+3...+100
ints=0,n=0;
do{
n++;
s+=n;
}while(n<100);
cout<<"s="<
//累加键盘输入的数据
doublex,sum=0.0;
do{
cout<<"x=";
cin>>x;
sum+=x;
}while(x!
=0);
cout<<"sum="<}
#include
main()
{
//计算和打印打印乘法九九表
for(inti=1;i<=9;i++){
cout<
for(intj=1;j<=9;j++)
cout<<'\t'<
cout<}
}
#include
main()
{
intx,sum=0;
//定义标号L1
L1:
cout<<"x=";
cin>>x;
if(x==-1)
gotoL2;//无条件转移语句,转到L2语句处
else
sum+=x;
gotoL1;//无条件转移语句,转到L1语句处
//定义标号L2
L2:
cout<<"sum="<}
#include
main()
{
//累加键盘输入的数据
doublex,sum=0.0;
while
(1){
cout<<"x=";
cin>>x;
if(x<=0)break;
sum+=x;
}
cout<<"sum="<}
#include
main()
{
inti;
for(i=1;i<=20;i++)
{
if(i%3==0)//能被3整除的整数,返回进行下次循环
continue;
cout<
}
cout<}
#include
main()
{
//声明数组和变量
inta[5],i,sum;
doubleavg;
//从键盘上循环为数组赋值
for(i=0;i<5;i++){
cout<<"a["<
cin>>a[i];
}
//直接显示数组元素
cout<//利用for循环显示数组各元素的值
for(i=0;i<5;i++)
cout<cout<//计算数组元素之和,并显示计算结果
sum=a[0]+a[1]+a[2]+a[3]+a[4];
cout<<"sum="<//利用循环计算数组的累加和
for(sum=0,i=0;i<5;i++)
sum+=a[i];
//显示累加和及平均值
cout<<"sum="<avg=sum/5.0;
cout<<"avg="<}
#include
main()
{
inti,max,index,a[5];
//从键盘上为数组赋值
for(i=0;i<=4;i++)
{
cout<<"a["<
cin>>a[i];
}
//利用循环遍历数组,找出最大值的元素及其下标
max=a[0];
for(i=0;i<=4;i++)
{
if(max{
max=a[i];
index=i;
}
}
cout<<"\nMax="<}
#include
#definesize5
main()
{
//声明变量
inti,j;
floatt,a[size];
//从键盘上为数组赋值
for(i=0;i{
cout<<"a["<