C 语言实例 – 输出数组

C语言教程评论

C 语言实例 - 输出数组

使用 for 循环输出数组:

实例

#include <stdio.h>

int main() {
   int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
   int loop;

   for(loop = 0; loop < 10; loop++)
      printf("%d ", array[loop]);

   return 0;
}

输出结果为:文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-shuchushuzu.html

1 2 3 4 5 6 7 8 9 0

使用 for 循环逆向输出数组:文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-shuchushuzu.html

实例

#include <stdio.h>

int main() {
   int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
   int loop;

   for(loop = 9; loop >= 0; loop--)
      printf("%d ", array[loop]);

   return 0;
}

输出结果为:文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-shuchushuzu.html

0 9 8 7 6 5 4 3 2 1
文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-shuchushuzu.html文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-shuchushuzu.html
运营不易,
感谢支持!
weinxin
我的微信
我的微信公众号
我的微信公众号扫一扫
weinxin
我的公众号
 
公式库网
  • 本文由 公式库网 发表于 2021年12月7日20:30:51
  • 转载请务必保留本文链接:https://www.gongshiku.com/html/202112/c-yuyanshili-shuchushuzu.html

发表评论