程序运行结果练习题

程序运行结果练习题
程序运行结果练习题

一、程序运行结果

1、假设数据表文件成绩表中有“总分”字

段,运行下列程序段

Use 成绩

X1=0

SCAN

X1=MAX(总分,X1)

Endscan

?X1

RETURN

执行该程序后X1显示的值为成绩表中的__________________________

2、clear

do A

return

procedure A

s=5

do B

?s

Return

Procedure B

S=S+10

Return

_______________________________ 3、set talk off

s=0

i=5

x=11

do while s<=x

s=s+1

i=i+1

enddo

?s

Set talk on

_____________________

4有如下程序,函数iif( )返回值是_____ *程序

Private X,Y

Stroe “男”to X

Y=len(X)+2

?iif(Y<4,”男”,”女”)

Return

4、s=0

for n=100 to1 step -1

s=s+n

endfor

?s

Return

________________

5、clear

set talk off

store 1 to i,a,b

do while i<=3

do prog1

“p(“+str(I,1)+”)=”+str(A,2)+”,”

i=i+1

enddo

??”b=”+str(b,2)

Return

Procdure prog1

a=a*2

b=b+a

set talk on

return

___________________

6、dime a(6)

a(1)=1

a(2)=2

for i=3 to 6

a(i)=a(i-1)+a(i-2)

next

?a(6)

____________________

7、accept to a

if A=[123]

s=o

endif

s=1

?s

_______________

8、clear

store 0 to a,b,s,i,j

do while i<=5

i=i+1

if i=3

a=s

j=i

loop

else

s=s+i

endif

if i=4

b=s+a

j=j+i

exit

else

s=s+i

endif

enddo

?S

___________

9、main.prg

set talk off

a=5

b=”c”

c=10

do p1 with b

?a,b,c

set talk off

return

p1.prg

parameters a

b=”a”

&b=&a

Do p2

?a,b,c

Return

p2.prg

if c=&b

return to master

else

return

endif

运行main.prg的结果为____________

11、set talk off

Dimension k(2,3)

i=1

do while i<=2

j=1

do while j<=3

k(i,j)=i*j

if int(k(i,j)/2)=k(i,j)/2

k(i,j)=k(i,j)+1

else

k(i,j)=k(i,j)-1

endif

??k(i,j)

??

j=j+1

enddo

?i=i+1

Enddo

Return

_________________

12、x=1

y=1

do while y<6

x=x*y

y=y+1

loop

print x

______________

13、m=1

Do while m<5

n=1

??m

Do while n<=m

tt=n+m

n=n+1

enddo

?

m=m+1

enddo

return

______________

14、主程序tt .prg

Public a

a=3

b=4

c=5

Do ss

?”2.a,b,c,d=”,a,b,cd

Return

运行tt 的结果是______ *ss.prg

Private c

a=a+1

b=10

c=20

d=30

?”1.a,b,c,d=”,a,b,c,d

return

15、x=2

Do while x<4

y=1

do while y<4

if x*y<5

?x,y

y=y+1

else

exit

endif

enddo

x=x+1

enddo

return

__________

16、x=1

y=20

edo while x

if mod(x,2)<>0

x=x^2+1

y=y+1

else

x=x+1

endif

enddo

?x

?y

_______________

17、n=3

do while n<=10

i=3

x=0

do while i<=n/2

if int (n/i)<>n/i

i=i+1

else

x=1

exit

endif

enddo

if x=0

??n

Endif

n=n+1

enddo

return

17、*pp.prg

Set talk off

x=5

y=10

set procedure to proc1

do p1

?x,y

Do p2

?x,y

Set procedure to

*proc1.prg

Procedure p1

x=x*5

y=y+5

return

procedure p2

x=10

y=x+20

return

18、set talk off

xs=0

for n=1 to 100

xs=xs+n

end for

?xs

Retrun

___________

19、set talk off

i=1

do while i<=4

j=1

do while j<=5

??”*”

j=j+1

enddo

?

i=i+1

enddo

20、SET TALK OFF

CLEAR

X=1

S=0

DO WHILE X<3

S=S+LC(X)

X=X+1

ENDDO

? S

SET TALK ON

RETURN

FUNCTION LC

PARAMETERS P

P=P+1

RETURN P*P

程序运行后,S的值是。

21、下面的程序运行后,变量N的值

为。

SET TALK OFF

CLEAR

S=0

FOR N=1 TO 10 STEP 3

IF N>10

EXIT

ENDIF

S=S+N

N=N+3

ENDFOR

?N

SET TALK ON

RETURN

22、数据表stud.dbf的内容如下:

记录号学号姓名性别出生日期专业特长

政治面貌

1 990001王晓东男 10/03/80 应用数学书法

团员

2 990002 李子清男 05/12/79 应用数学运动党员

3 990003 赵小芳女 02/16/80 应用数学舞蹈团员

8 990103 曲丽芳女 03/03/78 计算机应用摄影团员

CLEA

USE STUD

SCAN FOR 性别="男"

?RECNO(),编号

ENDSCAN

USE

RETU

输出结果为:。

23、set talk off

n=1

h=0.5

do while .t. h=h*2

if h>=16

exit

endif

n=n+1

enddo

?"循环次数为:",n

执行结果为:。

24、已知有数据库文件职工工资.dbc,数据

库中包含表“工资.dbf”,工资.dbf的表

结构为:

职工号(C,4),姓名(C,8),性别(C,

2),职称(C,8),基本工资(N,8,1)。

有Visual FoxPro程序5_2.prg如下:

CLEAR

OPEN DATABASE 职工工资

USE 工资

STORE 0 TO m,n

GOTO TOP

m=基本工资

n=基本工资

SCAN FOR 职称="副教授"

IF m<=基本工资

m=基本工资

ELSE

IF n>=基本工资

n=基本工资

ENDIF

ENDIF

ENDSCAN

?m

?n

该程序的功能是:

25、有如下Visual FoxPro程序:

SET TALK OFF

STORE 0 TO I,J

X=3

Y=0

DO P1 WITH X,Y

?X,Y

SET TALK ON

RETURN

PROCEDURE P1

PARAMETERS X,Y

I=1

DO WHILE I<=3

X=X+I

I=I+1

ENDDO

Y=X+Y

DO P2 WITH X

RETURN

PROCEDURE P2

PARAMETERS X

X=1

RETURN

运行上面的程序,显示的结果为:

26、有学生信息.dbf自由表,字段为:学号

(C,8),姓名(C,8),性别(C,2),

年龄(N,3,0),籍贯(C,20),入学成

绩(N,5,1),表中数据如下:

Record# 学号姓名性别年龄籍贯入学成绩

1 20100101 肖天海男 19 河北保定 560

2 20100102 王岩盐男 20 北京 623

3 20100103 刘星魂男 18 上海 559

4 20100104 张月新女 19 南京 610

5 20100201 李明玉男 20 江苏常州 623

6 20100202 季欣欣女 19 辽宁沈阳 580

7 20100203 王吉吉女 22 吉林长春612

有如下Visual FoxPro程序

SET TALK OFF

STORE 0 TO M,N

USE 学生信息

INDEX ON 性别 TAG 性别 OF ABSEX

SEEK "男"

DO WHILE 性别="男" AND .NOT.EOF()

N=N+1

M=M+年龄

SKIP

ENDDO

?M/N

SET TALK ON

运行上面的程序,显示的结果为:

写出下列程序运行结果

写出下列程序运行结果: 理解PRINT A=5:B=3 PRINT A,B,A+B END X=9:Y=7 PRINT "X=";X,"Y=";Y PRINT "X+Y=";X;"+";Y;"=";X+Y END A=4:B=7 PRINT "C=";A+B*2-A/2 END 理解变量(包括字符串变量) X=6:Y=0 PRINT X-2, X=X+7 PRINT “Y=”;X+2 PRINT Y END M=12:N=6 X=M/N:Y=M+N PRINT X,Y X=X+N:Y=M+X PRINT X,Y END A=7:B=4 A=A+B:B=A-B:A=A-B PRINT “A=”;A,”B=”;B END A$=”123”:B$=”321” C$=A$+B$ PRINT A$;”+”;B$;”=”;C$ END 理解INPUT INPUT X,Y C=X*Y PRINT “C=”;C END ? 4, 8 INPUT “A,B=”;A,B D=A+A+B+B PRINT D END A,B=? 2,3 绘图语句 SCREEN 12 LINE (100,100)-(400,300),2,B LINE (100,100)-(400,300),2 END SCREEN 12 LINE (100,100)-(400,100) LINE –(100,300) LINE –(100,100) END SCREEN 12 CIRCLE (200,200),100 LINE (200,100)-(200,300) LINE (200,200),(300,200)

END 简单函数 A=12.34: B=-5.34: C=0 D=A*A: E=B*B PRINT ABS(A),ABS(B),ABS(C) PRINT FIX(A),FIX(B),FIX(C) PRINT SQR(D),SQR(E) END A=3.14: B=A^2: C=-A D=FIX(A):E=ABS(C):F=SQR(B) PRINT ABS(D),E,F END 子字符串函数 A$=”123456789” L$=LEFT$(A$,4)+MID$(A$,3,3)+RIGHT$(A$,2) PRINT L$ END A$=”I am a student.” B$=”I like sing.” C$=”I often use computer.” D$=LEFT$(A$,2)+MID$(B$,3,5)+RIGHT$(C$,9) PRINT “D$=”;D$ END 读数置数语句 READ A,B,C PRINT A,B+C DATA 3,2,5 END READ X,Y PRINT “X=”;X,”Y=”;Y READ X PRINT X,Y DATA 3,2,5 END M=0 : READ A : M=M+A READ B : M=M+B PRINT M DATA 21,34,26 END 理解循环语句 FOR I=1 TO 10 STEP 3 PRINT “I=”;I,”I^2=”;I*I NEXT I END M=0 FOR A=2 TO 10 STEP 3 M=M+A NEXT A PRINT “M=”;M, “P=”;M/3 END 双重循环 FOR A=1 TO 3 FOR B=4 TO 5 PRINT A,B NEXT B NEXT A END FOR X=6 TO 10 STEP 2 FOR Y=5 TO 3 STEP –2 PRINT X-Y NEXT Y NEXT X

程序运行结果练习题

一、程序运行结果 1、假设数据表文件成绩表中有“总分”字 段,运行下列程序段 Use 成绩 X1=0 SCAN X1=MAX(总分,X1) Endscan ?X1 RETURN 执行该程序后X1显示的值为成绩表中的__________________________ 2、clear do A return procedure A s=5 do B ?s Return Procedure B S=S+10 Return _______________________________ 3、set talk off s=0 i=5 x=11 do while s<=x s=s+1 i=i+1 enddo ?s Set talk on _____________________ 4有如下程序,函数iif( )返回值是_____ *程序 Private X,Y Stroe “男”to X Y=len(X)+2 ?iif(Y<4,”男”,”女”) Return 4、s=0 for n=100 to1 step -1 s=s+n endfor ?s Return ________________ 5、clear set talk off store 1 to i,a,b do while i<=3 do prog1 “p(“+str(I,1)+”)=”+str(A,2)+”,” i=i+1 enddo ??”b=”+str(b,2) Return Procdure prog1 a=a*2 b=b+a set talk on return ___________________ 6、dime a(6) a(1)=1 a(2)=2 for i=3 to 6 a(i)=a(i-1)+a(i-2) next ?a(6) ____________________ 7、accept to a if A=[123] s=o endif s=1 ?s _______________ 8、clear store 0 to a,b,s,i,j do while i<=5 i=i+1 if i=3 a=s j=i loop else s=s+i endif if i=4 b=s+a j=j+i exit else s=s+i endif enddo ?S ___________ 9、main.prg set talk off a=5 b=”c” c=10 do p1 with b ?a,b,c set talk off return p1.prg parameters a b=”a” &b=&a Do p2 ?a,b,c Return p2.prg if c=&b return to master else return endif 运行main.prg的结果为____________ 11、set talk off Dimension k(2,3) i=1 do while i<=2 j=1 do while j<=3 k(i,j)=i*j if int(k(i,j)/2)=k(i,j)/2 k(i,j)=k(i,j)+1 else k(i,j)=k(i,j)-1 endif ??k(i,j) ?? j=j+1 enddo ?i=i+1 Enddo

MATLAB程序运行结果

close all %关闭打开了的所有图形窗口clc %清屏命令 clear %清除工作空间中所有变量%定义时间范围 t=[0:pi/10:8*pi]; y=sin(t); plot(t,y,'b:square')

close all clc clear %定义时间范围 t=[0:pi/20:9*pi]; grid on hold on %允许在同一坐标系下绘制不同的图形 plot(t,sin(t),'r:*') plot(t,cos(t)) plot(t,-cos(t),'k') %grid on %在所画出的图形坐标中添加栅格,注意用在plot之后4-1: close all clc clear %定义时间范围

t=[0:pi/20:9*pi]; hold on %允许在同一坐标系下绘制不同的图形 plot(t,sin(t),'r:*') plot(t,cos(t)) plot(t,-cos(t),'k') grid on %在所画出的图形坐标中添加栅格,注意用在plot之后hold off %覆盖旧图,自动把栅格去掉,且若要在加入栅格就 %必须把grid on加在plot后面 plot(t,-sin(t)) grid on

%主程序exp2_10.m global a %声明变量a为全局变量 x=1:100; a=3; c=prods(x) %调用子程序prods.m %子程序prods.m % function result=prods(x) % global a % result=a*sum(x); %声明了与主程序一样的全局变量a,以便在子程序中可以%使用主程序中定义的变量 答案:15150 exmdl2_1.m clear close all clc

C#程序题运行结果题

三写出运行结果题 (1) using System; class Program { static void Main() { int x = 3; Console.Write("星期:"); Console.WriteLine((Weekday)x); Console.Write("月份:"); Console.WriteLine((Month)x); Console.Write("季节:"); Console.WriteLine((Season)x); } enum Weekday { 未知 = -1, 星期天, 星期一, 星期二, 星期三, 星期四,星期五,星期六 } enum Month { 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月, 未知 = -1 } enum Season { 春, 夏 = 2, 秋 = 4, 冬 = 8 } } (2) using System; class Program { static void Main() { class1 c1 = new class1(); class1.y = 5; c1.Output(); class1 c2 = new class1(); c2.Output(); } } 星期:星期三月份:四月季节:3

public class class1 { private static int x = 0; public static int y = x; public int z = y; public void Output() { Console .WriteLine(class1.x); Console .WriteLine(class1.y); Console .WriteLine(z); } } (3) using System; class Program { static void Main() { IA ia = new B (); Console .WriteLine("{0} {1} {2} {4}", ia is IA , ia is IB , ia is A , ia is A , ia is B , ia is C ); } } public interface IA { } public interface IB : IA { } public class A : IA { } public class B : IB { } public class C : B , IB { } (4) using System; class Program { static void Main(string [] args) { MyClass y = new MyClass (); BaseClass x = y; x.i = 100; Console .WriteLine("{0}, {1}", x.i, y.i); } } class BaseClass { public int i; 0 5 0 0 5 5 True True False True

程序注释及运行结果

第二部分程序注释及运行结果 读者须知: 为了便于读者理解,现将光盘上第一部分可直接在MATLAB6.I 下运行的MATLAB程序的编号和书本上的内容对应如下,每个程序题目括号内的file.m是对应书本上的内容在光盘上第一部分的程序编号。 第二章的随机序列产生程序 例2.1 用乘同余法产生随机数(见光盘FLch2sjxleg1.m) ①编程如下: A=6; N=100; %初始化; x0=1; M=255; for k=1:N %乘同余法递推100次; x2=A*x0; %x2和x0分别表示x i和x i-1; x1=mod (x2,M); %将x2存储器的数除以M,取余数放x1(x i)中; v1=x1/256; %将x1存储器的数除以256得到小于1的随机数放v1中; )存放在矩阵存储器v的第k列中,v(:,k) v(:,k)=v1; % 将v1中的数( i %表示行不变、列随递推循环次数变化; x0=x1; %x i-1= x i; v0=v1; end %递推100次结束; v2=v %该语句末无‘;’,实现矩阵存储器v中随机数放在v2中,% 且可直接显示在MA TLAB的window中; k1=k; %grapher %以下是绘图程序; k=1:k1; plot(k,v,k,v,'r'); xlabel('k'), ylabel('v');tktle('(0-1)均匀分布的随机序列') ②程序运行结果如图2.5所示。

图2.5 采用MA TLAB产生的(0,1)均匀分布的随机序列图 ③产生的(0-1)均匀分布的随机序列 在程序运行结束后,产生的(0,1)均匀分布的随机序列,直接从MATLAB的window 界面中copy出来如下(v2中每行存6个随机数): v2 = 0.0234 0.1406 0.8438 0.0820 0.4922 0.9609 0.7852 0.7266 0.3750 0.2578 0.5508 0.3164 0.9023 0.4336 0.6094 0.6680 0.0234 0.1406 0.8438 0.0820 0.4922 0.9609 0.7852 0.7266 0.3750 0.2578 0.5508 0.3164 0.9023 0.4336 0.6094 0.6680 0.0234 0.1406 0.8438 0.0820 0.4922 0.9609 0.7852 0.7266 0.3750 0.2578 0.5508 0.3164 0.9023 0.4336 0.6094 0.6680 0.0234 0.1406 0.8438 0.0820 0.4922 0.9609 0.7852 0.7266 0.3750 0.2578 0.5508 0.3164 0.9023 0.4336 0.6094 0.6680 0.0234 0.1406 0.8438 0.0820 0.4922 0.9609 0.7852 0.7266 0.3750 0.2578 0.5508 0.3164 0.9023 0.4336 0.6094 0.6680 0.0234 0.1406 0.8438 0.0820 0.4922 0.9609 0.7852 0.7266 0.3750 0.2578 0.5508 0.3164 0.9023 0.4336 0.6094 0.6680 0.0234 0.1406 0.8438 0.0820

C++程序与运行结果

Class #include class X { int V alue; public: X(int v=0) { V alue = v; cout<<"X::X("<

5、以下程序运行结果:________。 funa(int a) {int b=0; static int c=0; a=c++,b++; return (a); main() {int a=3,i,k; for(i=0;i<2;i++) k=fun(a++); printf("%d\n",k); } 6、下面程序的运行结果:_____________ struct stu {int num; char name[10]; int age; } void fun(struct stu *p) {printf("%s\n",(*p).name); } main() {struct stu students[3]={{2010,"zhang",20},{2011,"wang",19},{2012,"zhao",18}; fun(students+2); } 7、下面程序的运行结果是:_________。 main() {int i,j,k=5; for(i=0;i<2;i++) {k++; {int k=0; for(j=0;j<=3;j++) {if(j%2)continue; k++;} } k++;} printf("k=%d\n",k); } 8、下面程序的运行结果是:_________。 main() {int a[5]={1,3,5,7,9},x,y,*p; p=&a[0]; x=*(p+2) y=*(p+4); printf("%d ,%d , %d\n",*p,x,y); } 9、下面程序的运行结果是:_________。 #include "stdio.h" int k=1; main( )

C语言程序及其运行结果一览表

关于数组 1.利用一维数组输出0~20的偶数 程序:#include void main(void) { int x[20],i; for(i=0;i<20;i++) x[i]=i; for(i=0;i<20;i+=2) printf("%3d\n",x[i]); } 结果: 2.求Fibonacci数列的前二十项 程序:#include void main(void) { int i; int f[20]={1,1}; for(i=2;i<20;i++) { f[i]=f[i-2]+f[i-1]; } for(i=0;i<20;i++) { if (i%5==0) printf("\n"); printf("%5d",f[i]); } printf("\n"); } 结果:

3.求10个整形数中最大数,最小数及其所在的位置。(有些地方不太能搞懂。) 程序:#include void main(void) { int a[10],i,imax,imin,d,x; for(i=0;i<10;i++) scanf("%d",&a[i]); d=x=0; for(i=1;i<10;i++) { if (a[i]>imax) { imax=a[i]; d=i; } if(a[i]

程序: #include void main(void) { int x[10],i,sum=0; for(i=0;i<10;i++) scanf("%d",&x[i]); for(i=0;i<10;i++) sum=sum+x[i]; printf("sum=%d\n",sum); for(i=9;i>=0;i--) printf("%3d",x[i]); printf("\n"); } 结果: 5.将10个整形数按从小到大的顺序排列并输出。(冒泡法的基本思想:通过相邻两个数的比较和交换,使数值较小的数逐渐从底部移向顶部,数值较大的数从顶部移向底部。像水底的气泡一样逐渐向上冒,故而得名。) 程序: #include void main(void) { int a[10],i,j,temp; printf("input ten numbers:\n"); for(i=0;i<10;i++) scanf("%d",&a[i]); for(i=0;i<9;i++) { for(j=0;j<9-i;j++) if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } printf("the sorted numbers:\n"); for(i=0;i<10;i++) printf("%3d",a[i]);

Java运行程序写结果

Java练习题 四、运行程序写结果 1. 当在命令提示符后输入”java SumTest 4 5”之后,下列程序的输出结果为: 4+5=9 public class SumTest { public static void main(String[] args) { int a, b, sum; a=Integer.parseInt(args[0]); b=Integer.parseInt(args[1]); sum=a+b; System.out.println(a + "+" + b + "=" + sum); } } 2. 当在命令提示符后输入”java PrintStar 8”之后,下列程序的输出结果为:(A12) ******** public class PrintStar { public static void main(String[] args) { int n = Integer.parseInt(args[0]); int i; for( i=1; i<=n; i++) System.out.print("*"); System.out.println(); } } 3. 当在命令提示符后输入”java CalculateTest 5.5”之后,下列程序的输出结果为: 10.0 public class CalculateTest{ public static void main(String args[]){ float x,y; x = Float.parseFloat(args[0]); if(x<1) y = x; else if(1<=x&&x<10)

写出程序的运行结果

#include void swap(int *x,int *y) { int t; t=*x;*x=*y;*y=t; } main() { int a,b; scanf("%d,%d",&a,&b); swap(&a,&b); printf("%d,%d\n",a,b); } 输入3,5,则显示__5,3___ 2.写出程序的运行结果 #include void swap(int *x,int *y) { int *t; t=x;x=y;y=t; } main() { int a,b; scanf("%d,%d",&a,&b); swap(&a,&b); printf("%d,%d\n",a,b); } 输入3,5,则显示___3,5___ 3.写出程序的运行结果 #include void swap(int *x,int *y) { int t; t=*x;*x=*y;*y=t; printf("%d,%d\n",*x,*y); } main() { int a,b; scanf("%d,%d",&a,&b); swap(&a,&b); printf("%d,%d\n",a,b); } 输入3,5,则显示__ 5,3 5,3

#include void swap(int *x,int *y) { int *t; t=x;x=y;y=t; printf("%d,%d\n",*x,*y); } main() { int a,b; scanf("%d,%d",&a,&b); swap(&a,&b); printf("%d,%d\n",a,b); } 输入3,5,则显示___5,3 3,5_

MATLAB_程序运行结果

MATLAB程序及运行结果 >>【%第1题】 [x,y]=meshgrid(-3:0.1:3) %创建网格数据 z=3.*(1-x).^2.*exp(-x.^2-(y+1).^2)... -10.*(x./5-x.^3-y.^5).*exp(-x.^2-y.^2)... -(1/3).*exp(-(x+1).^2-y.^2); %输入函数式 subplot(2,2,1); %设置2行2列的子图的第1图 mesh(x,y,z); %画出网状图 colormap(autumn) %当前图形窗的着色色图为autumn hidden off %显示遮住的部分 axis tight %把数据范围直接设置为坐标范围 title('表现图形的隐含部分') %设置标题 subplot(2,2,2) mesh(x,y,z) shading flat title('带阴影的三维图形') z=peaks(x,y); %计算函数值 subplot(2,2,3); meshc(x,y,z); %绘制带等高线的三维图形 title('带等高线的三维图形') subplot(2,2,4) contour3(x,y,z,20,'k'); %绘制三维图形的等高线 xlabel('X-axis'),ylabel('Y-axis'),zlabel('Z-axis') title('三维图形的等高线') 【运行结果略】 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ >>【%第2题】

%for循环: k=0;n=63; %设置初值 for i=0:1:63 %建立63次循环k=k+2.^i; sum(k) %累加 end %结束循环,并显示累加值k %WHILE循环: y=0;i=-1; while i<63; i=i+1; y=y+2^i; y=y+2.^i; end y % 避免循环: n=63; i=1:1:n; k=sum(2.^i) ans =1 ans =3 ans =7 ans =15 ans =31 ans =63 ans =127 ans =255 ans =511 ans =1023 ans =2047 ans =4095 ans =8191 ans =16383 ans =32767 ans =65535 ans =131071 ans =262143 ans =524287 ans =1048575 ans =2097151 ans =4194303 ans =8388607 ans =16777215 ans =33554431 ans =67108863 ans =134217727 ans =268435455 ans =536870911 ans =1.0737e+009 ans =2.1475e+009 ans =4.2950e+009

循环:程序阅读,写出程序的运行结果

一、程序阅读,写出程序的运行结果 1)program p431; var i,s,t:integer; begin t:=0; s:=0; for i:= -5 to 5 do begin t:=t+1; s:=s+t+i; end; writeln('s,t=',s:10,t:10); end. {结果为:} 2)program p432; var p,m:integer; begin p:=20; m:=2; repeat p:=p-m; m:=m+3; until m>p; writeln('m,p=',m:10,p:10); end. {结果为:} 3)program p433; var a,n:integer; begin n:=6; a:=0; while n>1 do begin a:=1; repeat

write('*'); a:=a+1; until a>=n; writeln; n:=n-1; end; end. {结果为:} 4)program p434; var i,j,k,s:integer; begin s:=0; for i:=3 downto 1 do begin for j:=1 to 3 do begin k:=0; repeat k:=k+1; s:=s+k; until k=j; end; s:=s-k-1; end; write('s=',s); end. {结果为:} 5)program p5305; var s,i:integer; begin s:=0; for i:=1 to 100 do if (i mod 3=0) and (i mod 4=0) then s:=s+i; writeln('s=',s); end. {结果为:}

程序和运行结果

金牌的程序 clear clc X0=[5 16 16 28 32]; X1(1)=X0(1); [m,n]=size(X0); for i=2:n Y(i-1,1)=X0(i); X1(i)=X1(i-1)+X0(i); B(i-1,1:2)=[-0.5.*(X1(i-1)+X1(i)),1]; end R=inv(B'*B)*B'*Y u=R(2); a=R(1); for i=1:n+1 X(i)=(X0(1)-u/a)*exp(-(i-1)*a)+u/a; if i>=2 X01(i)=X(i)-X(i-1); else X01(i)=X(i); end end disp('中国前五届的奥运会获得的金牌数'); X0 disp('预测中国第29届获得的金牌数为'); X01(n+1) disp('预测值'); X01 disp('相对残差'); for i=1:n D(i)=abs(X0(i)-X01(i)); W(i)=D(i)/X0(i); end W for i=1:n y(i)=(min(D)+0.5*max(D))/(D(i)+0.5*max(D)); end r=sum(y)/n

QX0=X0(1:n)-X01(1:n); QX1(1)=QX0(1); for i=2:n QX1(i)=QX0(i-1)+QX0(i); QY(i-1,1)=QX0(i); QB(i-1,1:2)=[-0.5.*(QX1(i-1)+QX1(i)),1]; end QR=(QB'*QB)\QB'*QY; for i=1:6 QX(i)=(QX0(1)-QR(2,1)/QR(1,1))*exp(-(i-1)*QR(1,1))+QR(2,1)/QR(1,1); XX(i)=X(i)+QX(i); if i>=2 XX0(i)=XX(i)-XX(i-1); else XX0(i)=XX(i); end end disp('修改后预测中国第29届获得的金牌数为'); XX0(n+1) disp('修改后的预测值为'); XX0 for i=1:n D1(i)=abs(X0(i)-XX0(i)); W1(i)=D1(i)/X0(i); end disp('利用残差模型修改后的相对残差'); W1 for i=1:n y1(i)=(min(D1)+0.5*max(D1))/(D1(i)+0.5*max(D1)); end r1=sum(y1)/n t=[24 25 26 27 28]; t1=[24 25 26 27 28 29]; [u1,m]=lsqcurvefit(@gm11,[11,-0.2],t,X0); [u2,m]=lsqcurvefit(@gm11,[11,-0.2],t1,X01); x1=linspace(24,30); y1=(5-u1(1)/u1(2)).*exp(-(x1-24)*u1(2))+u1(1)/u1(2); y2=(5-u2(1)/u2(2)).*exp(-(x1-24)*u2(2))+u2(1)/u2(2); plot(t,X0,'r*',x1,y1,'b-',t1,X01,'o',x1,y2,'-g'); legend('','',0);

相关文档
最新文档