當前位置:首頁 » 編程語言 » c語言二維數組

c語言二維數組

發布時間: 2022-01-10 05:53:23

c語言二維數組

例如對整型二維數組a[3][2]賦值方法一:在定義的同時賦值 int a[3][2]={0};//所有數組元素均為0 方法二: int a[3][2]={1,2,3,4,5,6};//常規的賦值方法方法三: int a[3][2]={{1,2},{3,4},{5,6}};//分行的賦值方法方法四: int a[3][2]={{1,2},{0},{3}};//部分賦值方法,第一行元素的值分別為1,2,第二行元素值都是0,第三行第一個元素值為3,第二個元素值為0 方法五: int a[3][2];/先定義 for(i=0;i<=3;i++) //用雙重for循環賦值,i,j表示二維數組下標 for(j=0;j<=2;j++) scanf("%d",&a[i][j]); 希望對你有所幫助。

Ⅱ c語言二維數組的運用

#include<stdio.h>
#define MAX 100
#define LEN 80
main()
{
char text[MAX][LEN];
register int i,j,t;
for(t=0;t<MAX;t++)
{
printf("%d:",t);
gets(text[t]); /* 由於 text 定義為二維數組, 所以該循環體的作用就是:循環從鍵盤輸入 MAX-1 次字元串,並存入 text[t] 中,然後 t 依次遞增 1 */
if(!text[t][0]) /* 該語句用於判斷字元串是否到結尾?,如果到結尾了,即:text[t][0] = '\0',表示只輸入了一個回車符,則退出循環 */
break;
}
for(i=0;i<t;i++)
{
for(j=0;text[i][j];j++)
{
putchar(text[i][j]); /* 顯示 text 二維數組中的字元 */
putchar('\n');
}
}
}

Ⅲ c語言二維數組怎麼表示

int
a[m][n];//就表示一個m行n列的整型二維數組
在c語言中數組的下標是從0開始的所以,數組a的元素個數可以表示為:a[0][0]-a[m-1][n-1]
例如:
#include<stdio.h>
int main()
{
int a[3][2],i,j;//定義一個3行2列的整型二維數組a
for(i=0;i<3;i++)//依次給二維數組賦值
for(j=0;j<2;j++)
scanf("%d",&a[i][j]);
printf("\n");
for(i=0;i<3;i++){//輸出二維數組
for(j=0;j<2;j++)
printf("%d ",a[i][j]);
printf("\n");
}
return 0;
}
/*
運行結果:
1 2
3 4
4 5
1 2
3 4
4 5
*/

Ⅳ C語言二維數組

float a[10][3]; 存10個學生的3門成績
float b[10][2]; 存10個學生的3門成績 總分 和 平均分。
依次輸入每個學生的 3門成績。計算每人的 總分,計算每人的平均分。再輸出。
#include<stdio.h>
int main(){
float a[10][3];
float b[10][2];
int i,j;
for (i=0;i<10;i++){
printf("input Math Chinese English scores for student %d\n", i+1);
for (j=0;j<3;j++) scanf("%f",&a[i][j]);
};
for (i=0;i<10;i++) {
b[i][0]=0;
for (j=0;j<3;j++) b[i][0]=b[i][0]+a[i][j];
b[i][1]=b[i][0]/3.0;
};
for (i=0;i<10;i++) printf("Student %d, total=%g, mean=%g\n",i+1,b[i][0],b[i]
[1]);

return 0;
}

Ⅳ c語言二維數組求解答

第一個雙循環算的是第一行和最後一行的和,第二個雙循環是算第一列和最後一列的行(去掉了首尾兩行)

Ⅵ C語言二維數組

正要做練習題,剛好看到你這個問題,就順便做了~

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

void main()
{
int a[100][4], i, j, temp = 0;
int class1_top = 1, score1 = 0, class2_top = 1, score2 = 0, class3_top = 1, score3 = 0;//存放三門課程最高分,最高得分學號
int max_total_score = 0, topstudent = 1;//最高總分,最高總分學號
srand((unsigned)time(NULL));
printf(" 注冊號 課程1 課程2 課程3\n");
for(i = 0; i < 100; i++)
{
a[i][0] = i + 1;
printf("%6d", a[i][0]);
for(j = 1; j < 4; j++)
{
a[i][j] = rand() % 100;
printf("%6d", a[i][j]);
}
printf("\n");
}//以上為定義一個100行4列的數組,每一行第1列為學號,從1-100。每一行2-4列為每門課的成績,並對成績進行隨機數初始化。

//1.顯示出每一個學生3門課程的總分數。3.順便統計出最高總分和最高總分學號
for(i = 0; i < 100; i++)
{
printf("student%4d`s total score is: ", a[i][0]);
for(j = 1, temp = 0; j < 4; j++)
temp += a[i][j];
if(max_total_score < temp)
{
max_total_score = temp;
topstudent = i + 1;
}
printf("%4d\n", temp);
}
printf("the max total score is:%4d, the top student is:%4d\n", max_total_score, topstudent);

//2.每門課程最高得分,最高得分的學號
for(i = 0; i < 100; i++)
{
if(score1 < a[i][1])
{
score1 = a[i][1];
class1_top = i + 1;
}
if(score2 < a[i][2])
{
score2 = a[i][2];
class2_top = i + 1;
}
if(score3 < a[i][3])
{
score3 = a[i][3];
class3_top = i + 1;
}
}
printf("class1 highest score is:%4d,owenr is student%d\n", score1, class1_top);
printf("class2 highest score is:%4d,owenr is student%d\n", score2, class2_top);
printf("class3 highest score is:%4d,owenr is student%d\n", score3, class3_top);
}

Ⅶ c語言二維數組是怎麼回事

你可以這么理解,自然數的范圍內,一維數組就是數軸,從0開始[0], [1] ,[2] [3]。。。
二位數組就是坐標軸,等於有了坐標,[0][0], [0][1] ,[0][2],[1][1]....

Ⅷ c語言二維數組問題

#include "stdio.h"

int main()

{

int a[5][5]={{1,3,5,7,9},{11,13,15,17,19},{21,23,25,27,29},{31,33,35,37,39},{41,43,45,47,49}};

int b[5][5]={{2,4,6,8,10},{12,14,16,18,20},{32,34,36,38,40},{42,44,46,48,50},{52,54,56,58,60}};

int i,j;

printf("a數組: ");

for (i=0;i<5;i++)

{

for(j=0;j<5;j++)

printf("%3d ",a[i][j]);

printf(" ");

}

printf("b數組: ");

for (i=0;i<5;i++)

{

for(j=0;j<5;j++)

printf("%3d ",b[i][j]);

printf(" ");

}

for (i=0;i<5;i++)

{

b[i][0]=a[4][i];

b[i][4]=a[0][i];

}

printf("變化後的b數組: ");

for (i=0;i<5;i++)

{

for(j=0;j<5;j++)

printf("%3d ",b[i][j]);

printf(" ");

}

return 0;

}

熱點內容
聚合腳本平台 發布:2024-09-20 17:51:55 瀏覽:180
訪問攔截怎麼解除安卓 發布:2024-09-20 17:28:48 瀏覽:275
蘿卜干存儲 發布:2024-09-20 17:21:37 瀏覽:715
蘋果手機如何遷移軟體到安卓手機 發布:2024-09-20 17:21:34 瀏覽:692
查看伺服器ip限制 發布:2024-09-20 16:56:27 瀏覽:389
p搜系統只緩存1頁為什麼 發布:2024-09-20 16:48:51 瀏覽:839
上網的賬號和密碼是什麼東西 發布:2024-09-20 16:31:31 瀏覽:612
安卓手機王者榮耀如何調超高視距 發布:2024-09-20 16:31:30 瀏覽:428
安卓G是什麼app 發布:2024-09-20 16:23:09 瀏覽:81
iphone怎麼壓縮文件 發布:2024-09-20 16:08:18 瀏覽:356