检查的C中是否存在数组元素

检查的C中是否存在数组元素

本文介绍了++检查的C中是否存在数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了很多类似这样的主题,但它是有点对我来说太复杂了。

如何检查数组中的元素存在?

首先我声明数组,并把价值在里面。

 为(int类型l = 0; L< = 21,L ++){
        裙[L] = 1;
    }

,然后用另一个我想检查是否存在于其他任何数组元素在数组裙子[];

有没有把它写像这样的一种方式?

 的for(int k = 0; K< = N; k ++){
    如果(skaiciai [k]的!=裙[K]){
        反++;
    }
}


解决方案

循环:

 的for(int k = 0; K< = N; k ++){
    如果(skaiciai [k]的!=裙[K]){
        反++;
    }
}

只会在阵列相同的指数比较元素。嵌套循环都需要与外循环迭代结束在一个数组中的元素和内循环遍历元素其他数组中:

 的for(int k_skirt = 0; k_skirt< = N; k_skirt ++)
{
    对于(INT k_skaiciai = 0; k_skaiciai< = N; k_skaiciai ++)
    {
        如果(skaiciai [k_skaicia] ==裙[k_skirt]){
            反++;
        }
    }
}

I've found a lot of topics like this, but it was kinda too complicated for me.

How to check if element exists in an array?

first I declare an array and put values in it

for(int l=0;l<=21;l++){
        skirt[l]=l;
    }

and then with another for I'd like to check if any element which exist in other array is in array skirt[];

Is there a way to write it something like this?

for(int k=0;k<=n;k++){
    if(skaiciai[k]!=skirt[k]){
        counter++;
    }
}
解决方案

The loop:

for(int k=0;k<=n;k++){
    if(skaiciai[k]!=skirt[k]){
        counter++;
    }
}

would only compare elements at the same index in the arrays. Nested for loops are required with the outer for loop iterating over the elements in one array and the inner for loop iterating over elements in the other array:

for (int k_skirt = 0; k_skirt <= n; k_skirt++)
{
    for (int k_skaiciai = 0; k_skaiciai <= n; k_skaiciai++)
    {
        if(skaiciai[k_skaicia] == skirt[k_skirt]){
            counter++;
        }
    }
}

这篇关于++检查的C中是否存在数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:47