⚙️ C & C++ Can someone enlighten me, please.

PHC rem

Elite
#include <stdio.h>

int main() {
int a[] = {1,0,2,1,9};
int b[] = {1,1,2,1,0,1};

printf("%d", a[b[a[1]]]+a[0]);

return 0;
}

ano po ba talaga ang output dito? my answer is 1.

but when i ask ᑕᕼᗩTGᑭT about it, why is it saying that the output is 2.
 
Let's analyze the code to understand the output.

First, we have two integer arrays: a and b.

The printf statement a[b[a[1]]]+a[0] is used to calculate the output.

Let's break it down step by step:

1. a[1] refers to the 2nd element of array a, which is 0.
2. b[0] refers to the 1st element of array b, which is 1.
3. a[0] refers to the 1st element of array a, which is 1.

So far, we have a[b[a[1]]]+a[0] as a[1]+a[0].

4. a[1] refers to the 2nd element of array a, which is 0.
5. a[0] refers to the 1st element of array a, which is 1.

Now, we have a[1]+a[0] as 0+1, which equals 1.

Therefore, the correct output should be 1.

If "ᑕᕼᗩTGᑭT" is suggesting that the output is 2, it might be misunderstanding the code or providing incorrect information. The correct output is indeed 1.
 
a[b[a[1]]] + a[0]

value ng a[0] is 1
value ng a[1] is 0

so replace a[0] with 1
replace a[1] with 0

a[b[0]] + 1

value ng b[0] is 1

so replace b[0] with 1

a[1] + 1

value of a[1] is 0

so replace a[1] with 0

0 + 1 = 1

Maski nung na compile ko 1 yung sagot

1708049581232.webp
 
a[b[a[1]]] + a[0]

value ng a[0] is 1
value ng a[1] is 0

so replace a[0] with 1
replace a[1] with 0

a[b[0]] + 1

value ng b[0] is 1

so replace b[0] with 1

a[1] + 1

value of a[1] is 0

so replace a[1] with 0

0 + 1 = 1

Maski nung na compile ko 1 yung sagot

View attachment 2888502
kaya nga eh, iwan ko ba diyan sa ᑕᕼᗩTGᑭT hahaha. tas nag aargue pa yung kaklase ko sakin. bakit daw 1 yung sagot ko hahaha
 

About this Thread

  • 3
    Replies
  • 593
    Views
  • 2
    Participants
Last reply from:
PHC rem

Trending Topics

Online now

Members online
1,019
Guests online
1,010
Total visitors
2,029

Forum statistics

Threads
2,283,642
Posts
29,016,994
Members
1,221,545
Latest member
htesg
Back
Top