# How do I learn C? (was Computer project) [closed]

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={2, 3, 4, 5, 6, 7, 8,9};

void setup()
{
pinMode(pins, OUTPUT);
}

void loop()
{
x=random(0, 8);
digitalWrite(pins[x], HIGH);
delay(1000)
digitalWrite(pins[x], LOW);
delay(1000)
}
``````
• That's poorly stated homework since they only give one delay but expect patterned blinking. Anyway, approach this by imagining you are a robot being shown the numbers one at a time. What very efficient notes could you take on a re-writable scratchpad (ie, a minimal number of variables) It will help in finding the best solution if you assume the list of numbers could be arbitrarily long... – Chris Stratton Mar 11 '16 at 13:47
• @JRobert I'm stuck in the if statement and arrays I really can't understand them also there's supposed to be a for loop – user19167 Mar 11 '16 at 14:54
• How would you simulate this on paper/physically? For example, using N head-tail coins as LEDs..... – Dave X Mar 11 '16 at 16:54
• Well for one improvement, pins is undefined, since C indices start with 0, so there are only pins...pins defined in your code. Maybe you could use your for(;;) loop there? Also, try compiling your code--if the compiler detects and reports errors, it might help you refine your logic. – Dave X Mar 11 '16 at 16:59
• Frankly there is no sound reason to put the pins in an array at all, since their range is continuous. The only array needed is the input data. And only two local variables plus the iterator variable are required to solve the problem. Basically, writing code is premature. Figure out the algorithm. – Chris Stratton Mar 11 '16 at 18:20