读程序,请写出程序运行结果。#include #define N 7main(){ int a[N]; int i,j,t; for(i=1;ia[i+1]) { t=a[i]; a[i]=a[i+1]; a[i+1]=t; } } for(i=1;i[/i][/i]
举一反三
- 下面 rotate 函数的功能是:将 n 行 n 列的矩阵a 转置#define N 4 void rotate(int a[][N]) { int i,j,t; for(i=0;i 答案: (1) j (2) a[i][j]=a[j][i] 答案解析: 难易: 中 知识点:[/i][/i]
- 针对如下三个实现矩阵求和的不同函数: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
- 请写出输出结果______ ______ main ( ) { int a[5]={15, 23, 4, 67, 98}; int i, m, n; m=n=a[0]; for (i=1; i<5; i++ ) {if (m>a[ i ] ) m=a[ i ]; if (n
- 有以下程序:#includestdio.hvoid main(){int a[][3]={{1,2,3},{4,5,0}},(*pa)[3],i;pa=a;for(i=0;i3;i++) if(i2) pa[1][i] = pa[1][i]-1; else pa[1][i] = 1;printf(%d\n,a[0][1]+a[1][1]+a[1][2]);}执行后输出结果是( )。[/i][/i][/i] A: 9 B: 7 C: 0 D: 8
- 写出以下程序运行结果。 #include<iomanip.h> const int N=3; int main() { int a[N][N]={{7,-5,3},{2,8,-6},{1,-4,-2}}; int b[N][N]={{3,6,-9},{2,-8,3},{5,-2,-7}}; int i,j,c[N][N]; for(j=0;j<N;i++) //计算矩阵C for(j=0;j<N;j++) c[i][j]=a[i][j]+b[i][j]; for(j=0;j<N;i++) //输出矩阵C { for(j=0;j<N;j++) cout<<setw(5)<<c[i][j]; cout<<endl; } }[/i][/i][/i][/i]