Arrays - C++

Write down the output of the following code snippet:

Declarations:

num arr[6] = 3, 5, 1, 4, 2, 6
num array[6] = 10, 20, 30, 40, 50, 60
num val = 0
num start = 0
while val != 60
for i=start to 5 step 2
val = array[arr[i]-1]
output val
endfor
start = start + 1;
endwhile

What is this-

while val <> 60

Does it want to convey val!=60?

Can you possibly post the proper code with brackets? Its kind of confusing to look at.

BTW, output-

Your Output (stdout)
30
10
20
50
40
60

You could actually run it on the online compiler :stuck_out_tongue:

Your code Must be(Just guessing)

#include<iostream>
using namespace std;
int main()
{
   int arr[6] = {3, 5, 1, 4, 2, 6}; 
   int array[6] = {10, 20, 30, 40, 50, 60};
   int val = 0;
   int start = 0;
   int x[6];
   while(val!=60)
   {
   	for(int i=start;i<6;i++)
   	{
   		x[i]=array[arr[i]-1];
	}
	val=val+10;
   }
   for(int i=0;i<6;i++)
   cout<<x[i]<<endl;}

Output :

30
10
20
50
40
60

and meanwhile try to be specific what are you trying to say!

30
10
20
50
40
60

Your output is:
30
10
20
50
40
60

#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[] = {3, 5, 1, 4, 2, 6};
int array[] = {10, 20, 30, 40, 50, 60};
int val = 0;
int start = 0;
int i;
while(val != 60) {
for(i = start; i < 5 ;i++) {
val = array[arr[i]-1];
cout << val << endl;
}
start ++;
}
return 0;
}

Thank you.

Thank you.

You are welcome dear!! Feel free to ask any further doubts you might have. :slight_smile: