The last elements of arri and arrf are referenced as arri9 and arrf29 Similarly

The last elements of arri and arrf are referenced as

This preview shows page 2 - 4 out of 7 pages.

arri[0] and arrf[0]. The  last   elements of arri and arrf are referenced as arri[9] and arrf[29].  Similarly, the 5 th   element of arri can be referenced by arri[4], the 20 th   element of arrf can be  referenced as arrf[19] and so on. Note that when the arrays are declared their sizes are also  declared. Here the size of arri array is 10 and the size of arrf array is 30. Now, arri[0]…arri[9]  can have any integer  value say arri[3] = 123, arri[7] = 34; arrf[0]…to arrf[29] can have any float   value say arrf[2] = 23.56, arrf[23] = 222.567. The array size can also be given by using the define statement as shown below : #define SIZE1 10 #define SIZE2 100 int arri[SIZE1] ; float arrf[SIZE2] ; Using for Loops for Sequential Access of 1-D array elements : How to read numbers into arrays?: The numbers can be read into arrays by using for loop . Consider the following example: Example : float abc[25] ; int i ; for (i = 0; i < 25; ++i) { printf (“Enter the %d element \n”, i ) ;    scanf ( “%f”, &abc[i] ) ;                         } Page 2 of 7
Image of page 2
Here, the variable abc is declared as an array  of size  25 consisting of float  values. An integer   variable i is declared to be used as a subscript for the array. Next, for loop  is used starting from 0  and ending at 24 which is the range of the array abc. Inside the loop the printf statement asks the  user to enter the particular element of the array and scanf reads that element. Note that here also  the address operator &  and the name of the array  is used but the subscript is added so that all the  elements can be read. The %f operator is used because the array is of float type. How to print numbers from arrays ? : The numbers can be printed from arrays by using for loop . Consider the following example: Example : double abc[50] ; int n ; for (n = 0; n < 50; ++n) {                          printf (“The %dth  element of array is %lf\n”, n, abc[n]) ;                     } The printing of array is similar to reading. Here also for loop
Image of page 3
Image of page 4

You've reached the end of your free preview.

Want to read all 7 pages?

  • Spring '10
  • zaman
  • Array, ARRI

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes