DEV Community

Tania
Tania

Posted on • Originally published at kodlogs.com

How to check if all elements in a array are equal

An array is a very simple and important topic. In programming, if you are creating a program, an array makes our task very easy. Like other variables, arrays also need to be introduced. Suppose you have variables of the same data type, then you find it very difficult to name them separately. We need to do this. We need a suitable method in which we can easily use the same type of data type. An array is provided to solve this problem. With the help of this we can use different suffixes or numbers for the same variable name. Used to save different items by counting. In programming language it is called subscript .

Today we will create two arrays to see if they are equal or not. It is important that the data type and length of the array should be the same if the data is in a character or in a float or a string. If the first index has value kodlogs and the second index has the same value then they will be equal otherwise they will not be. Let's take two arrays then we use loop or solve it with the help of conditional operator so that you can Visit our website kodlogs to get more information like this.

Example:-

Input  : arr1[] = {1, 2, 5, 4, 0};
         arr2[] = {2, 4, 5, 0, 1}; 
O/P : Yes

Input  : arr1[] = {1, 2, 5, 4, 0, 2, 1};
         arr2[] = {2, 4, 5, 0, 1, 1, 2}; 
O/P : Yes

Input : arr1[] = {1, 7, 1};
        arr2[] = {7, 7, 1};
O/P: No
Enter fullscreen mode Exit fullscreen mode

Top comments (0)