Suppose i have array of 10 elements in it how to access 5 element from the array using sup script and index?

Showing Answers 1 - 17 of 17 Answers

deviprasad

  • Oct 22nd, 2005
 

 Per suppose array variable name is ARRAY then  ARRAY[5] will give the

5th element of the array

  Was this answer useful?  Yes

soumya_dev

  • Feb 27th, 2006
 

Hi,

  Use appropriate subscript value for accessing array ariable values..Using perform or someother verbs...

   Use appropriate index value..ie.,Disposition value for accessing index variable values...For this use up by/down by verbs..

  

  Was this answer useful?  Yes

if you have an array with 10 elements like this :

 int a[] = {1,2,3,4,5,6,7,8,9,10};

To access the 5th element, you need to write a[4]. Because, Array index starts from 0. In this case 0th element is 1, 1st element is 2.. etc

  Was this answer useful?  Yes

Bhanu

  • Apr 6th, 2006
 

hi;

as u answeres the question; array[5] will be the 5th element, but it will access the 6th element coz array initialisation starts from 0, i.e. array[0] will be the first element and array[4] will be th 5th element.

  Was this answer useful?  Yes

Srinivas

  • May 15th, 2006
 

I guess array starts from 0 in c and C++ languages, But in COBOL the array 1st element starts from 1 NOT 0.

vijayakumar

  • May 19th, 2006
 

Declare the Subscipt and initilaize. 

eg:- I = 0;

PERFORM UNTIL I < 5

WS-VAR1 = ARRAY(I)

DISPLAY 'THE VALUE OF ARRAY', I 'IS', WS-VAR1

I = I +1

END PERFORM.

Rohini

  • May 27th, 2006
 

Hi ,

In COBOL, the array index starts from 1 and not 0.

The fifth element can be accessed as :

 array [5]

or using a Perform clause with subscript starting from 1 to 5 increasing by 1.

Thanks.

 

if you just want to access fifth element from array in COBOL you won't need neither subscript nor index. ARRAY(5) will give your fifth element from the array.

subscript or index you need for an access to the elements through variable rather than direct random access.

indexes as oppose to subscripts are low-level variable types that can be altered by arithmetic operations or SETting them to the specific positive integer value (or zero). you can't move values onto the index or initialize them. you normally recognize indexes as opposed to subscript by INDEXED BY Array-Index PIC S9(4) COMP-3. using indexes oppose to subscripts you access elements of the array by relative byte address which has greater efficiency than using subscripts.

subscripts are trivial numeric variables.

  Was this answer useful?  Yes

sandeep

  • Nov 12th, 2006
 

Useless

in cobol array starts from 1.dumb maniac.

  Was this answer useful?  Yes

talluri

  • Jul 27th, 2011
 

USING INDEX

set IX1 is 1.
perform varying from 1 by one until IX1>5
read sno(IX1)
read sname(IX1)
set IX1 up by 1
end-perform.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions