arry with loops
how to Check if the array is equal. Two arrays are
equal if their sizes are same, and elements with same index from both arrays are same. Display both arrays. Display if the array is equal or not equal. no one was able to answer this question any help (edited)
46 Replies
yes its in my uni and need to do it with loop
no one was able to answe it
the teacher said set your own arry value
array*
this is the full q
from the array it self
like the length
count
so array from 0
but the value in it start from 1
Do you know how to get the length?
int[,] arr = ( (1, 2, 3), (4, 5, 6 ), ( 7, 8, 9} };
for example this got 2 array
Right ?
0 1 2
yes i know
Diddy#2634
REPL Result: Success
Console Output
Compile: 587.518ms | Execution: 64.545ms | React with ❌ to remove this embed.
this one i dont know
i don’t know how to compare vvalues
Are you actually trying to do this for multi-dimensional arrays?
Maybe i can declare tow array then loop them?
if(int x= 5; )
wait wait let me try
shit i give up
oh yaaaaa
yes yes
Diddy#2634
REPL Result: Success
Console Output
Compile: 582.625ms | Execution: 33.080ms | React with ❌ to remove this embed.
let me try
First i will declare toe arrays
then i will do the calculation u ask me
wait please
but i am confused
there is tow type of array
which one i declare
What do you mean exactly?
type 1.....int[,] arr = new int[,]{{1,2,3},{4,5,6},{7,8,9}};
type2...• int[] arr = new int[5]{ 10, 20, 30, 40, 50 };
how i knows in he future if he want the first type?
2d array?
Multi-dimensional arrays are kind of special purpose - like for defining a grid or matrix.
Most uses of arrays are the single dimensional kind.
int[] arr = { 10, 20, 30, 40, 50 };
int[] arr1 = { 5, 22, 63, 70, 80 };
if(arr == arr1)
System.Console.WriteLine("they are equal");
else
{
System.Console.WriteLine("they are not equal");
}
this better
Unfortunately this way of checking array content's equality wouldn't work in c#
i am using Visual Studio
then how to make it work in c#
ohhhh
yes in this uni must Visual studio code
i had long dilemma with the teacher end up his winning and my lost lol
hmmm i am confused how to do thta
that
yes
ohhhh so array cant because not specific number
yes there is
arr.length ?
but how to cod it nicely me try
like that?
feels wrong
i try this too
but obviously wrong
hard
In an if statement you'll do
(expression) == (expression)
expression here can be any value or variable
So the first expression
you have is
arr=arr.Length
second expression
arr1=arr1.Length
What these expressions mean
They mean assign arr.Length to arr
and assign arr1.Length to arr1
That obviously wouldn't work because
1- arr1 and arr1.Length have different types
2- the expressions can't be comparedi am just a little confused now lol
then how
now?
it must be this Visual headache i kill u slowly program
if {} ?
so if can be () and {}
what is the difference ?
i notice for loop (FOR) always ()
like this
ok ok noted
and elements with same index from both arrays are same.
what is that
i don’t understand index,
ohhhhh
i have an idea yea
so in q want me to delete.
i didn’t know that
the rest of the q
yes i am trying
Diddy#2634
REPL Result: Success
Console Output
Compile: 573.979ms | Execution: 64.356ms | React with ❌ to remove this embed.
is this real person ?
ok following u
if ?
if(arr[0] ==arr1[0]); ?
heheh u are amazing teacher
ok
ohhh yea yea
then how
for(int a=0; a=<5; a++)
yes sooo ok
for(arr[,]=0; arr[,]=>....... i can’t figure the rest
nested loop ?
Diddy#2634
REPL Result: Success
Console Output
Compile: 648.189ms | Execution: 73.027ms | React with ❌ to remove this embed.
Can you write this exact same loop but make it go as many times as there are items in the array?
why $
Diddy#2634
REPL Result: Success
Console Output
Compile: 723.539ms | Execution: 72.182ms | React with ❌ to remove this embed.
i will try this
i dont understand what he mean
put the last index number
hmmm
how ya
lol
arr.lengthlast
arr.lenght-1
Oh your loop I commented on isn't actually correct
=<
Thats not a thing
Just use <
so for(arr[] < arr.length-1 ?
or just follow this lol
for(i=0; i=>arr.length-1; i++)
var currentIndex = i;
var currentArrayValue = arr[i];
ok i am officially lost
can just explain this to me
You need to study how for loops work
And learn what operators are valid
=> is not a valid operator
in a for loop
You want the less than operator
<=
i mean this
Yes that's better
Although we usually do:
i < arr.Length
instead of i <= arr.Length - 1
ohhhh
yesss
Finally
thanks for everything
You're still not checking whether they are equal or not.