资源预览内容
第1页 / 共6页
第2页 / 共6页
第3页 / 共6页
第4页 / 共6页
第5页 / 共6页
第6页 / 共6页
亲,该文档总共6页全部预览完了,如果喜欢就下载吧!
资源描述
Program and list(应用程序和目录)01. BAS 求和a+aa+aaa+aaaa+.+aaa.a(a大于等1小于等于9的整数 Input “a=”;a Input “n=”;n T=0 S=0 i=1 While i=n T=10*t+a S=s+t I=i+1 Wend Print “s=”,send 02. BAS 求和a+aa+aaa+aaaa+.+aaa.a(a大于等1小于等于9的整数Input “a=”;a Input “n=”;n T=0 S=0 i=1 While i0 thenPrint “absolute value is”;xelseIf x=0 thenPrint “absolute value is”;0 ElsePrint “abosolute value is”;-xEnd ifEnd ifend06.ABS任给一个自然数a( 输出aaaaa(n个a组成的n位数)Input “a=”;aInput “n=”;nS=0i=1while i=n s=s+10(i-1)i=i+1wendlet s=a*sprint send 07.BAS求和: Input “n=”;n i=1 s=0while i=0 thenLet p=-b/(2*a)Let q=SQR(d)/(2*a)If d=0 thenPrint “the equation is one real root”;pElseX1=p+qX2=p-qPrint “two difference root”Print “x1=”;x1;”x2=”;x2End if End if End09.ABS解二元一次方程组 Program:Input a1,b1,c1,a2,b2,c2 m=a1*b2-a2*b1 p=b1*c2-b2*c1 q=c1*a2-c2*a1if m0 then x=p/m y=q/m print “x=”;x;”y=”;yelse if p=0 or q=0 then print “this binary linear equation group has numberless solution” else print “this binary linear equation group has no solution” end if end if end 10BASaN,1a9,求a+aa+aaa+aaaa+.+aaa.a 的值 Program:Input “a=”;aInput “n=”;nLet i=1Let s=0dos=s+10(i-1)i=i+1loop until inlet s=a*sprint :s=”;send11.BAS 求两个正整数的最大公约数 【辗转相除法】program:input “m=”;minput “n=”;nif m0r= m mod nif r=0 thenprint “the greatest common divisor of m and n is”;nelsem=nn=rend ifwendend12.BAS 把三个数a,b,c按从大到小的顺序排列input a,b,cif ab then t=a a=b b=tend ifif ac then t=a a=c c=tend ifif b=b then if a=c then if b=c then print a,b,c else print a,c,b end if else print c,a,b end ifelseif b=c then if a=c then print b,a,c else print b,c,a end if else print c,b,aend ifend ifend 14.BAS 任给一个大于1的自然数,判断这个数的奇偶性。programinput “n=”;nif n=2 then print “the number you input is a prime”else i=2 do r=n mod i i=i+1 loop until in-1 or r=0 if r=0 then print “the number is not a prime”elseprint “the number is a prime” end ifend ifend15.BAS求和: input “n=”;ni=1s=0 while in print “s=”;send17.求一个数的方根,开方(The extraction of a root of a quantity) (extraction of root)方根,开方 program: input x,n m=1/n y=xm print y end18.BAS 求一个数的算术平方根 program: input “x=”;x if x=0 then print “arithmetic square root is”;sqr(x) else print “no arithmetic square root” end ifend19BAS 判断年份是闰年的程序input “your year is”;xif x mod 4=0 and x mod 1000 then print “the year is leap year”else if x mod 400=0 then print “the year is leap year” else print “the year is not leap year” end ifend ifend20.BAS计算当x=1,2,320时,函数 的函数值x=1while x 20end22.BAS (阶乘factorial)用程序计算n的阶乘input “n=”;nif n=0 then print “0!=1”else if n=1 theni=1f=1while i=nf=f*ii=i+1print “the number factorial is”;f wend end ifend if end如果输出语句改为:print n; “!=”;f则屏幕显示为:n!=f0!=11!=12!=23!=64!=245!=12023BAS 输出1到100之间的偶数PROGRAM:i=1While i=100i=i+1r=i mod 2if r=0 thenPrint i;end if WendEnd说明:输出语句末加分号表示按行输出,否则按列输出24BAS 输出1到100之间的偶数PROGRAM:i=1doi=i+1r=i mod 2if r=0
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号