How to extract numbers from an array in C language?

In C language, you can extract numbers from an array using indexes. Each element in the array has a corresponding index, starting from 0 and increasing. Indexes can be used to access elements in an array.

Here is an example code that demonstrates how to extract numbers from an array.

#include <stdio.h>

int main() {
   int arr[] = {1, 2, 3, 4, 5};  // 定义一个整型数组

   // 从数组中抽取第一个数字(下标为0)
   int num1 = arr[0];
   printf("抽取的数字为:%d\n", num1);

   // 从数组中抽取第三个数字(下标为2)
   int num2 = arr[2];
   printf("抽取的数字为:%d\n", num2);

   return 0;
}

The output result is:

抽取的数字为:1
抽取的数字为:3

In the previous example, we defined an integer array called arr and initialized it with some numbers. By using the format arr[index], we can extract specific numbers and store them in corresponding variables.

bannerAds