Jump to content

Displaying part of an array and generating a random data set multiple times

- - - - -

  • Please log in to reply
2 replies to this topic

#1
sadi039

sadi039

    Newbie

  • Members
  • Pip
  • 2 posts
Hello!
I am working on a C# assignment for a class:

I am having trouble displaying the first and last 20 numbers of the array.
Also..I need help with part B, as I do not know how I can iterate a loop so that it displays 10 random sets of data

Edited by sadi039, 21 February 2012 - 09:10 AM.


#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
'foreach' does exactly that: for each. Meaning it iterates over everything. You only want to iterate over the first and last 20 elements. For that you need a couple of standard 'for' loops.

For printing the first 20 elements, you can start by initializing your loop iterator at zero and incrementing it till it's less than 20. Easy enough. For the last 20 elements, you need to initialize the loop iterator at Length-20 and increment it till it is less than Length.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
sadi039

sadi039

    Newbie

  • Members
  • Pip
  • 2 posts
Thank you!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users