您好,欢迎访问三七文档
写出程序的运行结果辅导例1:写出下列程序的运行结果:#includestdio.hmain(){floatx,y;scanf(“%f”.&x);if(x0.0)y=0.0;elseif((x5.0)&&(x!=2.0))y=1.0/(x+2.0);elseif(x10.0)y=10.0;printf(“%f\n”,y);}输入2.0↙参考答案:0.50000?例2:写出下列程序的运行结果:#includestdio.hmain(){intnum=0;while(num=2){num++;printf(“%d\n”,num);}}参考答案:123例3:写出下列程序的运行结果:#includestdio.hmain(){inta,b;for(a=1,b=1;a=100;a++){if(b=20)break;if(b%3==1){b+=3;continue;}b-=5;}Printf(“%d\n”,a);}参考答案:8例4:写出下列程序的运行结果:#includestdio.hmain(){intx=1,y=0,a=0,b=0;switch(x){case1:switch(y){case0:a++;breakcase1:b++;break;}case2:a++;b++;break;printf(“%d%d\n”,a,b);}参考答案:21#includestdio.hmain(){intk=4,m=1,p;p=func(k,m);printf(“%d,”p);p=func(k,m);printf(“%d\n”p);}例5:写出下列程序的运行结果:func(inta,intb){staticintm=0,i=2;i+=m+1;m=i+a+b;return(m);}参考答案:8,17例6:写出下列程序的运行结果:intd=1;fun(intp){intd=5;d+=p++;printf(“%d”,d);}main(){inta=3;fun(a);d+=a++;printf(“%d\n”,d);}参考答案:84例9:写出下列程序的运行结果:#includestdio.h#defineSUB(X,Y)(X)*Ymain(){inta=3,b=4;printf(“%d\n”,SUB(a++,b++));}参考答案:12例10:写出下列程序的运行结果:#includestdio.h#includestring.hvoidfun(char*w,intm){chars,*p1,*p2;p1=w;p2=w+m-1;while(p1p2){s=*p1++;*p1=*p2--;*p2=s;}}main(){chara[]=“ABCDEFG”;fun(a,strlen(a));puts(a);}参考答案:AGAAGAG
本文标题:程序的运行结果
链接地址:https://www.777doc.com/doc-7026041 .html