正确定义了i,j,sum三个变量,下列程序片段运行结束后sum的值是( )for(i=2;i<7;i++){ sum=1; for(j=i;j<7;j++) sum=sum+j; }
A: 48
B: 49
C: 1
D: 7
A: 48
B: 49
C: 1
D: 7
举一反三
- 以下程序的运行结果是( <br/>)。 #includevoid main() { int i,j,sum=0; for(i=1;i<=2;i++) { for(j=1;j<=2;j++) sum+=i*j; } printf("%d",sum); } A: 3 B: 5 C: 7 D: 9
- 执行以下程序段后sum的值?int i,j,sum=0;for(i=1;i<=5;i++){ for(j=1;j<=5;j+=2) sum=sum+1;} A: 25 B: 15 C: 50 D: 5
- 下列程序执行后,sum的结果是________。Dim sum As IntegerFor i = 1 To 4 Step 2 For j = 1 To i Step 2 sum += j NextNext A: 6 B: 9 C: 5 D: 7
- 下面程序用来计算1+1/2!+1/3!+…1/10!,请完善程序。#includeintmain(){inti,j;sum=0,fac;for(i=1;i<=10;i++){fac=1;for(j=1;j<=i;j++)fac=fac*j;sum=sum+1/fac;}printf("%f",sum);return0;}
- 针对如下三个实现矩阵求和的不同函数:int a[N][N];int sumA( int a[N][N] ){ int i, j; int sum = 0; for ( i = 0; i < N; i++ ) for ( j = 0; j < N; j++ ) sum += a[i][j]; return sum;}int sumB( int a[N][N] ){ int i, j; int sum = 0; for ( j = 0; j < N; j++ ) for ( i = 0; i < N; i++ ) sum += a[i][j]; return sum;}int sumC( int a[N][N] ){ int i, j; int sum = 0; for ( j = 0; j < N; j+=2 ) for ( i = 0; i < N; i+=2 ) sum += ( a[i][j] + a[i+1][j] + a[i][j+1] + a[i+1][j+1] ); return sum;}当N足够大的时候,三个函数的运行时间t1、t2、t3符合下列哪种情况?()[/i][/i][/i][/i] A: t1 > t2 > t3 B: t3 > t1 > t2 C: t2 > t3 > t1 D: t3 > t2 > t1