正确定义了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
D
举一反三
- 以下程序的运行结果是( <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
内容
- 0
以下程序运行后,输出的结果是( ) main() { int i, j ,sum=0; for (i=5;i;i--) for (j=0;j<3;j++) sum++; printf("%d",sum); }
- 1
下面约束段语句表达正确的是 A: @for(wh(i):@sum(vd(j):x(i,j))<=a(i)); B: for(wh(i):@sum(vd(j):x(i,j))<=ai(i)); C: @for(wh(i):@sum(vd(j):x(i,j))<=a(i); D: @for(wh(i):sum(vd(j):x(i,j))<=ai(i));
- 2
下面模型段语句表达错误的是 A: min=@sum(links(i,j):c(i,j)*x(i,j)); B: min=@sum(links:c*x); C: @for(vd(j):@sum(wh(i):x(i,j))=d(j)); D: @sum(vd(j):@for(wh(i):x(i,j))=d(j));
- 3
下面程序可求出矩阵a的主对角线上的元素之和,请填空。 main() {inta[3][3]={1,3,5,7,9,11,13,15,17},sum=0,i,j; for(i=0;i<3;i++) for(j=0;j<3;j++) if(_____)sum=sum+_______; printf("sum=%d ",sum); }
- 4
如下代码 int sum=0; for(i=1;i[=10;i++) for(j=1;j<=10;j++) { sum=sum+i*j; <br] } A: 55 B: 550 C: 3025 D: 10