本文目錄一覽:
- 1、C語言二維數組?
- 2、C語言編程 二維數組
- 3、c語言中的二維數組?
- 4、c語言二維數組
C語言二維數組?
#include stdio.h
int main()
{
int score[5][3];
float ave_score_1[5];
float ave_score_2[3];
int i,j;
int sum_score;
printf(“Please input the score:\n”);
for(i=0;i5;i++)
{
scanf(“%d %d %d”,score[i][0],score[i][1],score[i][2]);
}
for(i=0;i5;i++)
{
sum_score = 0;
for(j=0;j3;j++)
{
sum_score += score[i][j];
}
ave_score_1[i] = sum_score / 3.0;
}
for(j=0;j3;j++)
{
sum_score = 0;
for(i=0;i5;i++)
{
sum_score += score[i][j];
}
ave_score_2[j] = sum_score / 5.0;
}
for(i=0;i5;i++)
{
printf(“%f “,ave_score_1[i]);
}
printf(“\n”);
for(j=0;j3;j++)
{
printf(“%f “,ave_score_2[j]);
}
return 0;
}
C語言編程 二維數組
1 方法:通過嵌套的兩個for循環來遍歷二維數組
2 代碼
#includestdio.h
void Find(int num, int arr[3][2], int row, int col){
for (int i = 0; i row; i++){
for (int j = 0; j col; j++){
if (arr[i][j] == num){
printf(“找到了,行列下標為(%d,%d)\n”, i, j);
return;
}
}
}
puts(“沒找到”);
}
int main(){
int arr[3][2] = { { 1, 2 }, { 3, 4 }, { 5, 6 } };
int num;
scanf(“%d”, num);
Find(num, arr, 3, 2);
getchar();
getchar();
return 0;
}
c語言中的二維數組?
C 語言中的多維數組(multidimensional array)其實就是元素為數組的數組。n 維數組的元素是 n-1 維數組。例如,二維數組的每個元素都是一維數組,一維數組的元素當然就不是數組了。
多維數組聲明時,每個維度用一對方括號來表示:char screen[10][40][80]; // 一個三維數組
數組 screen 包含 10 個元素,從 screen[0] 到 screen[9]。每個元素又是一個二維數組,它有 40 個元素,這 40 個元素均是一維數組,然後每個一維數組內都有 80 個字符。整體來說,screen 數組有 32000(10×40×80)個 char 類型元素。
想要獲取該三維數組 screen 內的某個 char 元素,必須指定 3 個索引值。例如,下面的語句把字符Z寫入該數組的最後一個元素位置:screen[9][39][79] = ‘Z’;
c語言二維數組
1、首先是定義一個二級指針和行列變量【int **array,row,column;】。
2、然後編寫輸入行列的語句,代碼如圖。
3、接下來就可以為其開闢一個一個一維裝着一維數組的數組。
4、接下來使用【array[i]=(int *)malloc(sizeof(int)*column);】,為數組再次產生一個新的裝着數組的數組。
5、然後就可以為其賦值並輸出【代碼如圖】,就完成了。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/286951.html