#include <stdio.h>

#define SIZE 10

int main() {
    int arr[SIZE];
    int x;
    int i, count = 0;
    
    // 输入10个整数保存到数组中
    for (i = 0; i < SIZE; i++) {
        scanf('%d', &arr[i]);
    }
    
    // 输入要查询的整数x
    scanf('%d', &x);
    
    // 遍历数组查找x出现的位置
    for (i = 0; i < SIZE; i++) {
        if (arr[i] == x) {
            printf('%3d', i);
            count++;
        }
    }
    
    // 如果未查询到x,输出'Not Found'
    if (count == 0) {
        printf('Not Found');
    }
    
    return 0;
}
C语言代码:查找数组中元素出现的位置

原文地址: https://www.cveoy.top/t/topic/o8AM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录