1、1高中数学 第一章 算法初步 1.2 基本算法语句教材习题点拨 新人教 A版必修 3练习1.程序:INPUT “F”;FC(F32)*5/9PRINT “C”;CEND2.程序:INPUT “a,b”;a,bsumabdiffabmula*bdiva/bPRINT sum,diff,mul,divEND3.程序如下:INPUT a,b,cp(abc)/2tp*(pa)*(pb)*(pc)sSQR(t)PRINT sEND4.程序:INPUT “a,b,c”;a,b,csum10.4*a15.6*b25.2*cPRINT “sum”;sumEND2练习1.程序:INPUT “a,b,c” ;a,
2、b,cIF abc AND acb AND bca THENPRINT “YES”ELSEPRINT “NO”END IFEND2.点拨:本程序要求输入一个正的两位数 x.若 9 x100,则先取出 x的十位,记作a,再取出 x的个位,记作 b,把它们调换位置,然后输出.如输入 25,则输出 52.3.程序:INPUT “Please input an integer:”;aIF a MOD 20 THENPRINT “Even.”ELSEPRINT “Odd.”END IFEND4.程序:INPUT “Please input a year:”;yby MOD 4cy MOD 100dy M
3、OD 400IF b0 AND c0 THENPRINT “Leap year.”ELSEIF d0 THENPRINT “Leap year.”ELSE3PRINT “Not leap year.”END IFEND IFEND点拨:对一个年份是否是闰年需要分多种情况考虑,对于不同的情况分类必须清楚,如“能被 4整除但不能被 100整除,或者能被 400整除” ,在“能被 4整除但不能被 100整除”这句话中就包括了“不能被 400整除” ,所以对“能被 400整除”的数需要重新加以限定,才能得出正确答案.练习1.程序:INPUT “n”;ni2DOrn MOD i;ii1LOOP UNTI
4、L in1 OR r0IF r0 THENPRINT “n不是质数.”ElsePRINT “n是质数.”END IFEND2.程序:INPUT “n”;ni1f1WHILE inff*iii14WENDPRINT fEND习题 1.2A组1. ).0(1,xy2.程序:INPUT “a,b,h”;a,b,hpabSp*h/2PRINT “S”;SEND3.程序:INPUT “n”;ni1sum0WHILE insumsum(i1)/iii1WENDPRINT “sum”;sumENDB组1.程序:INPUT “a,b,c”;a,b,cINPUT “r,s,t”;r,s,tda*sr*bIF d
5、0 THEN5x(s*cb*t)/dy(a*tr*c)/dPRINT “x,y”;x,yELSEPRINT “Please input again.”END IFEND2.程序:n1p1 000WHILE n7pp*(10.5)nn1WENDPRINT pEND3.程序:INPUT “x”;xIF x1 THENyxELSEIF x10 THENy2*x1ELSEy3*x11END IFEND IFPRINT “y”;yEND4.解:INPUT “请输入数字 a和加数的个数 n:” ;a,n6S0i1IF a9 OR n0PRINT “error”ELSEIF a9 and a1 THENbaEND IFEND IFDOSSbbb*10aii1LOOP UNTIL inPRINT “S”;SEND