查找最大数、排序、矩阵等
2020-12-13 04:34
标签:*打印 矩阵 main printf 元素 乘法 class std 打印 例1 寻找最大数 #include main() { int i,max,a[]={4,8,1,3,6,9,10,2}; max=a[0]; for(i=1;i
{ if ( a[i]>max) max=a[i]; } printf("\max=%d\n",max); } 例2 寻找最大数和最大数的位置 #include main() { int i,p,max,a[]={4,8,1,3,6,9,10,2}; max=a[0]; p=0; for(i=1;i
{ if ( a[i]>max) { max=a[i]; p=i; } } printf("max=%d p=%d \n",max,p+1); } 例3 排队问题一 #include main() { int i,j,p,max,a[]={4,8,1,3,6,9,10,2}; j=0; aa: max=a[j]; p=j; for(i=j+1;i
{ if ( a[i]>max) { max=a[i]; p=i; } } a[p]=a[j]; a[j]=max; j++; printf("max=%d p=%d \n",a[j],a[p]); if(j
goto aa; for(i=0;i
printf("a[%d]=%d \n",i,a[i]); } 例4 排队问题二 #include main() { int i,j,p,max,a[]={4,8,1,3,6,9,10,2}; for (j=0;j
{ max=a[j]; p=j; for(i=j+1;i
{ if ( a[i]>max) { max=a[i]; p=i; } } a[p]=a[j]; a[j]=max; printf("max=%d p=%d \n",a[j],a[p]); } for(i=0;i
printf("a[%d]=%d \n",i,a[i]); } 例5 排序问题(沉底法) #include main() { int i,j,p,a[]={2,6,3,5,7,8,1}; for(i=0;i
printf("%d ",a[i]); printf("\n" ); for(j=0;j
for(i=0;i
if(a[i]>a[i+1]) { p=a[i]; a[i]=a[i+1]; a[i+1]=p; } for(i=0;i
printf("%d ",a[i]); printf("\n" ); } 例2-1 寻找最大数 #include main() { int i,j,p,max,a[3][3]={4,8,1,3,26,9,10,2,15}; for (i=0;i
{ for(j=0;j
printf("%2d ",a[i][j]); printf("\n"); } max=a[0][0]; for (i=0;i
for(j=0;j
if ( a[i][j]>max) max=a[i][j]; printf("\n%d ",max); } 例2-2 寻找最大数和最大数的位置 #include main() { int i,j,pi,pj,max,a[3][3]={4,38,1,3,26,9,10,2,15}; for (i=0;i
{ for(j=0;j
printf("%2d ",a[i][j]); printf("\n"); } max=a[0][0]; for (i=0;i
for(j=0;j
if ( a[i][j]>max) { max=a[i][j]; pi=i; pj=j; } printf("\n%d %d %d ",max,pi+1,pj+1); } 例3-1 矩阵乘法一(求第i行第j列元素) #include main() { int i,j,k,a[3][3]={4,38,1,3,26,9,10,2,15},b[3][4]={1,3,4,7,9,1,4,2,11,6,8,3},c[3][4]; for (i=0;i
{ for(j=0;j
printf("%2d ",a[i][j]); printf("\n"); } printf("\n"); for (i=0;i
{ for(j=0;j
printf("%2d ",b[i][j]); printf("\n"); } /*求矩阵c[i][j]*/ i=1; j=2; c[i][j]=0; for(k=0;k
{ c[i][j]=c[i][j]+a[i][k]*b[k][j]; printf("%d %d \n",a[i][k],b[k][j]); } printf("%d %d %d\n",i,j,c[i][j]); } 例3-2 矩阵乘法二(求第i行元素) #include main() { int i,j,k,a[3][3]={4,38,1,3,26,9,10,2,15},b[3][4]={1,3,4,7,9,1,4,2,11,6,8,3},c[3][4]; for (i=0;i
{ for(j=0;j
printf("%2d ",a[i][j]); printf("\n"); } printf("\n"); for (i=0;i
{ for(j=0;j
printf("%2d ",b[i][j]); printf("\n"); } /*求矩阵c[i][j]*/ i=1; for (j=0;j
{ c[i][j]=0; for(k=0;k
{ c[i][j]=c[i][j]+a[i][k]*b[k][j]; printf("%d %d \n",a[i][k],b[k][j]); } printf("%d %d %d\n",i,j,c[i][j]); } } 例3-3 矩阵乘法三(求所有元素) #include main() { int i,j,k,a[3][3]={4,38,1,3,26,9,10,2,15},b[3][4]={1,3,4,7,9,1,4,2,11,6,8,3},c[3][4]; for (i=0;i
{ for(j=0;j
printf("%2d ",a[i][j]); printf("\n"); } printf("\n"); for (i=0;i
{ for(j=0;j
printf("%2d ",b[i][j]); printf("\n"); } /*求矩阵c[i][j]*/ for(i=0;i
for (j=0;j
{ c[i][j]=0; for(k=0;k
{ c[i][j]=c[i][j]+a[i][k]*b[k][j]; printf("%d %d \n",a[i][k],b[k][j]); } printf("%d %d %d\n",i,j,c[i][j]); } for (i=0;i
{ for(j=0;j
printf("%3d ",c[i][j]); printf("\n"); } } 查找最大数、排序、矩阵等 标签:*打印 矩阵 main printf 元素 乘法 class std 打印 原文地址:https://www.cnblogs.com/duanqibo/p/11113476.html