當前位置:首頁 » 編程語言 » c語言34矩陣增加一列
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言34矩陣增加一列

發布時間: 2022-06-24 13:26:55

A. C語言程序:有一個3*4的矩陣,要求編寫一個程序找出每一行中的最大值並與第一列交換

到底是行數是3 還是列數是3?
我姑且認為是行數是3 然後把一行4個數字里找出最大的放在這一行的第一個
如果是這樣子 寫個循環函數就好了
假設矩陣數值保存在 QZ[3][4]中
int rows=3,cols=4;
int itemp=0;//假設矩陣里的值是整數
for(int i=0;i<rows;i++)
{//遍歷每一行
for(int j=cols-1;j>0;j--)
{//從最後一列開始 把大的數字移到前一列
if(QZ[rows][cols]>QZ[rows][cols-1])
{//如果後一列數字大於前一列數字 交換
itemp = QZ[rows][cols-1];
QZ[rows][cols-1] = QZ[rows][cols];
QZ[rows][cols]=itemp;
}
}
}
這樣應該能解決你的問題吧 當然我沒去試 沒有純C的環境 而且這個實在不算難

B. C語言:有一個3*4的矩陣,要求編寫求這個二維數組中的最大的那個元素的值,以及所在的行號和列號。

摘要 #include

C. C語言,我想定義一個函數實現矩陣相加功能,可是矩陣最少也要輸入一個列數,我想讓行列數都是變數,這個

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedefstructmatrix
{
int**array;
introw;
intcolumn;
}MATRIX,*PMATRIX;
voidaddMatrix(PMATRIXa,PMATRIXb,PMATRIXc)
{
inti,j,k;
if(a->row!=b->row||a->column!=b->column)
{
printf("矩陣A%d*%d與矩陣B%d*%d大小不同,不支持加法運算 ",
a->row,a->column,b->row,b->column);
c->row=0;
c->column=0;
return;
}
c->row=a->row;
c->column=a->column;
c->array=(int**)malloc(c->row*sizeof(int*));
if(c->array==NULL)
{
printf("分配內存失敗 ");
c->row=0;
c->column=0;
return;
}
for(i=0;i<a->row;i++)
{
*(c->array+i)=(int*)malloc(c->column*sizeof(int));
if(*(c->array+i)==NULL)
{
printf("分配內存失敗 ");
c->row=i-1;
freeMatrix(c);
return;
}
memset(*(c->array+i),0,c->column*sizeof(int));
for(j=0;j<a->column;j++)
*(*(c->array+i)+j)=*(*(a->array+i)+j)+*(*(b->array+i)+j);
}
}

D. C語言:有一個3*4的矩陣,要求編寫一個程序找出每一行中的最大值並與第一列交換

#include <stdio.h>
main(void)
{
int a[3][4],j,i,k,max=0,t;
for(j=0;j<3;j++)
for(i=0;i<4;i++)
scanf("%d",&a[j][i]);
for(j=0;j<3;j++)
{
for(i=0;i<4;i++)
if(max<a[j][i])
{
max=a[j][i];
k=i;
}
{t=a[j][k];a[j][k]=a[j][0];a[j][0]=t;}
}

printf("\n");
for(j=0;j<3;j++)
{
for(i=0;i<4;i++)
printf("%d ",a[j][i]);
printf("\n");
}
}

E. 用C語言編程,輸入一個3*4整數矩陣並且求各行元素之和和各列元素之和

1.
#include <stdio.h>
int main()
{
int a[3][4]={0};
int i,j,max,max_i,max_j;
printf("Please input a 3X4 matrix:\n");
for(i=0;i<3;i++)
for(j=0;j<4;j++)
scanf("%d",&a[i][j]);
max=a[0][0];
max_i=max_j=0;
for(i=0;i<3;i++)
for(j=0;j<4;j++)
if(a[i][j]>max)
{
max=a[i][j];
max_i=i;
max_j=j;
}
printf("The max is %d,row %,col %d\n",max,max_i,max_j);

}

2.
#include <stdio.h>
int main()
{
char a[100]={0};
int i,count=0;
printf("Please input a string:");
gets(a);
for(i=0;a[i]!='\0';i++)
if(a[i]==' ')
count++;

printf("The string contents %d space\n",count);

}