C语言_数组_举例演示[3.2]

  • 一维数组
#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

发布了80 篇原创文章 · 获赞 0 · 访问量 1752

猜你喜欢

转载自blog.csdn.net/weixin_41272269/article/details/104147787