user19167: Can you help me writing a code for this question guys??
You have an Arduino Uno with 8 LEDs connected to digital pins 2 to 9.
Create an array of 8 elements. Fill it with random numbers between 2 and 9 (all inclusive)
Write a program which determines the greatest number among them. Save this number in a variable named max. Print this number on serial monitor. Blink the LED connected to this number. Let the delay time be 0.5 second. 
Note that the random function may result in duplicate numbers generated. For example, the generated array may be {3,4, 4, 7,6, 2,5,7}
The maximum number will be 7.Since it occurred twice in the array, then you should blink it twice ^_^
It the maximum number occured 3 times in the array, then you should blink it 3 times, and so for any number of occurrences 
I have written this so far but I'm sure it's all wrong
int pins[8]={2, 3, 4, 5, 6, 7, 8,9};

void setup() 
{
   pinMode(pins[8], OUTPUT);
}

void loop() 
{
    x=random(0, 8);
    digitalWrite(pins[x], HIGH);
    delay(1000)
    digitalWrite(pins[x], LOW);
    delay(1000)
}


user313: First hint: pinMode() only applies to one pin at a time. You'll need to execute it 8 times to intialize 8 I/O pins' modes.
Second hint: As @ChrisStratton tried to suggest, generate the random number set first; then "figure out" (set some variables in memory that will tell you) what do with the terminal output and the digital I/Os; then do each of those things. It helps to partition a larger problem into smaller ones.
Update: Considering your updated title, How do I learn C?, and since the question reads like a homework assignment, aren't you already taking a class in C or C++? If so, how do you find it lacking, i.e., what additional resources or direction would be most helpful to you? There are a number of good books on the C language, and one of those would be a good place to start. If you don't already have a favorite one, you can't go wrong with The C Programming Language, by Brian Kernighan & Dennis Ritchie, the authors/designers of the C language and its early compilers. It is book on the C language, not on programming per-se, so if you are new to programming as well, a programming tutorial would be an excellent additional choice (sorry I don't have one to recommend).
Secondly, beat up on the example programs that come with the ArduinoIDE: click the "Open" button [uparrow icon on the IDE toolbar; not the File | Open menu] and you'll see a menu of your current sketches and, below the break, categories of example programs. Pick one of the examples, read it and try to understand what it does and why it is written the way it is. Then tweak the ###p out of it - both to understand how make it behave differently, and to break it. You'll learn a lot by a) interpreting error messages from the compiler, and b) finding and fixing your mistakes. If you're not breaking your programs at least twice as often as you're succeeding, you're not trying hard enough!

19167: <p>Can you help me writing a code for this question guys??
You have an Arduino Uno with 8 LEDs connected to digital pins 2 to 9.
Create an array of 8 elements. Fill it with random numbers between 2 and 9 (all inclusive)
Write a program which determines the greatest number among them. Save this number in a variable named max. Print this number on serial monitor. Blink the LED connected to this number. Let the delay time be 0.5 second. </p>

<p>Note that the random function may result in duplicate numbers generated. For example, the generated array may be {3,4, 4, 7,6, 2,5,7}</p>

<p>The maximum number will be 7.Since it occurred twice in the array, then you should blink it twice ^_^
It the maximum number occured 3 times in the array, then you should blink it 3 times, and so for any number of occurrences </p>

<p>I have written this so far but I'm sure it's all wrong</p>

<pre><code>int pins[8]={2, 3, 4, 5, 6, 7, 8,9};

void setup() 
{
   pinMode(pins[8], OUTPUT);
}

void loop() 
{
    x=random(0, 8);
    digitalWrite(pins[x], HIGH);
    delay(1000)
    digitalWrite(pins[x], LOW);
    delay(1000)
}
</code></pre>
 313: <p>First hint: pinMode() only applies to one pin at a time. You'll need to execute it 8 times to intialize 8 I/O pins' modes.</p>

<p>Second hint: As @ChrisStratton tried to suggest, generate the random number set first; then "figure out" (set some variables in memory that will tell you) what do with the terminal output and the digital I/Os; then do each of those things. It helps to partition a larger problem into smaller ones.</p>

<p>Update: Considering your updated title, <em>How do I learn C?</em>, and since the question reads like a homework assignment, aren't you already taking a class in C or C++? If so, how do you find it lacking, i.e., what additional resources or direction would be most helpful to you? There are a number of good books on the C language, and one of those would be a good place to start. If you don't already have a favorite one, you can't go wrong with <em>The C Programming Language</em>, by Brian Kernighan &amp; Dennis Ritchie, the authors/designers of the C language and its early compilers. It is book on the C language, not on programming per-se, so if you are new to programming as well, a programming tutorial would be an excellent additional choice (sorry I don't have one to recommend).</p>

<p>Secondly, beat up on the example programs that come with the ArduinoIDE: click the "Open" button [uparrow icon on the IDE toolbar; not the File | Open menu] and you'll see a menu of your current sketches and, below the break, categories of example programs. Pick one of the examples, read it and try to understand what it does and why it is written the way it is. Then tweak the ###p out of it - both to understand how make it behave differently, and to <strong>break</strong> it. You'll learn a lot by a) interpreting error messages from the compiler, and b) finding and fixing your mistakes. If you're not breaking your programs at least twice as often as you're succeeding, you're not trying hard enough!</p>
