- 一维数组
#include<stdio.h>
int main(){
int number[10]; //定义一个int类型的数组,大小是10
int i,j,n;
//循环赋值,从11开始。
for(i=0;i<10;i++){
number[i] = i+10;
}
//循环打印数组。
for(j=0;j<10;j++){
n = number[j];
printf("number[%d]is:%d\n",j,n);
}
return 0;
}
- 二维数组
#include<stdio.h>
int main(){
int number[3][4]; //定义一个3行4列的int数组
int i,j;
//循环给数组赋值。
for(i=0;i<3;i++){
for(j=0;j<4;j++){
number[i][j]=i*100+j;
}
}
//循环打印数组。
for(i=0;i<3;i++){
printf("the %d row: ",i);
for(j=0;j<4;j++){
printf("%d ",number[i][j]);
}
printf("\n");
}
return 0;
}
root@jiang-pc:/home/jiang/work# ./a.out
the 0 row: 0 1 2 3
the 1 row: 100 101 102 103
the 2 row: 200 201 202 203