025.多维数组
一维数组和二维数组其实并没有本质的区别.
但是在不同的场合下,二维数组表达更加形象化.
姓名 | 分数 |
A | 98 |
B | 97 |
C | 99 |
D | 98 |
二维数组
#include<stdio.h>
#include<stdlib.h>
void
main() {
int l_v1[4][2] = { {'A',98},
{ 'B',97
},
{'C',99},
{'D',98} };
for (size_t i = 0; i < 4;
i++)
{
printf("姓名:%c 分数:%d\n", l_v1[i][0], l_v1[i][1]);
}
system("pause");
}
姓名 | 年龄 | 身高 |
A | 25 | 176 |
B | 13 | 151 |
C | 47 | 167 |
#include<stdio.h>
#include<stdlib.h>
void
main() {
int l_v1[3][3] = { {'A',25,176},
{ 'B',13,151
},
{'C',47,167} };
for (size_t i = 0; i < 3; i++)
{
printf("姓名:%c 年龄:%d 身高:%d\n", l_v1[i][0], l_v1[i][1], l_v1[i][2]);
}
system("pause");
}
#include<stdio.h>
#include<stdlib.h>
void main() {
int l_name[] = { 'a','b','c','d' };
int l_height[] = { 170,175,174,168 };
for (size_t i = 0; i < 4; i++)
{
printf("%c %d\n", l_name[i], l_height[i]);
}
system("pause");
}
#include<stdio.h>
#include<stdlib.h>
void main() {
int l_nameage[4][2] = {
{'a',30},
{'b',25},
{'c',23},
{'d',19}
};
for (size_t i = 0; i < 4; i++)
{
printf("%c %d\n", l_nameage[i][0], l_nameage[i][1]);
}
system("pause");
}
#include<stdio.h>
#include<stdlib.h>
void main() {
int l_nameageheight[4][3] = {
{ 'a',30 ,160},
{ 'b',25 ,170},
{ 'c',23 ,165},
{ 'd',19 ,167 }
};
for (size_t i = 0; i < 4; i++)
{
printf("%c %d %d\n", l_nameageheight[i][0], l_nameageheight[i][1], l_nameageheight[i][2]);
}
system("pause");
}