![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2006
Posts: 2
Rep Power: 0
![]() |
A simple programming question
hi..
i was thrown this question yesterday from a friend of mine.. Using a single processor, an algorithm to compute the sum of eight numbers held in an array can be expressed as follows: set sum to zero set counter to zero WHILE counter < 8 Do increment counter by 1 add number [counter] to sum ENDWHILE output sum The same operation of summing eight numbers can be executed by using four processors in parallel. Describe, how this could be done in C#? Any suggestions? i know you are grouping integers and possibly passing parameters.. but then since i have just started to learn C#, i can't exactly come up with such a code... |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 211
Rep Power: 3
![]() |
Hello, and welcome to the forums.
This is a good item to read about how to post to get better responses. What type of solution are you looking for? Are you just talking about using different threads to compute the array or actually using different computers? If it's the first you'd need to do threading (System.Threading) otherwise you'd need to use sockets and encoding and other communication protocols to ensure the computers are sending information back and forth correctly. Either way if you're just learning C# this probablly isn't a good place to start unless you've had experience doing this type of thing with other languages. -MBirchmeier |
|
|
|
|
|
#3 | |
|
Programming Guru
![]() ![]() ![]() |
Quote:
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
|
#4 | |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 630
Rep Power: 4
![]() |
Quote:
Hehe ![]()
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
|
#5 | |
|
Newbie
Join Date: Jan 2006
Posts: 2
Rep Power: 0
![]() |
hi.
well.. thanks for the replies. sorry for not explaining the problem in more detail. also, noted that this isnt the place for newbies. I guess an early end to my venture on programming forums. besides; this is actually a past exam question which my friend showed me when we were going through past papers, and if you are familiar with the British A-level curriculum, you will understand how much high level programming they teach you in high-school (close to nothing). Well, i did modify this question slightly, towards the end i said "using C#" and in the exam paper it actually said "using a diagram".... so basically i'd be using the pairwise addition method to draw a diagram outlining how an algorithm of such type will function.. not writing an algorithm... ..but as with every human mind.. curiosity got the better of me and i probably made a "mistake" of posting this question here... hoping to see a few useful replies that'd point me in the right direction.. i thought id learn something, try it out and hopefully understand C# better as i learn it... but i guess people like me are viewed here as asking these questions to pass their term papers or whatever. Thanks anyway. Quote:
Thank you all anyhow. |
|
|
|
|
|
|
#6 | ||
|
Programmer
Join Date: Jan 2006
Location: Dallas, TX
Posts: 49
Rep Power: 0
![]() |
Quote:
Quote:
![]() |
||
|
|
|
|
|
#7 | |
|
Programmer
Join Date: Jan 2006
Location: Dallas, TX
Posts: 49
Rep Power: 0
![]() |
Quote:
Because of this, I do understand suspicion, if there is any, but I prefer to give any person posting a question the benefit of the doubt.Most programming forums have similar rules to prevent students from cheating. (Cheating can produce sub-standard programmers, which devalues our profession (livelihood), so you can see that it's a dead serious issue.) This means that we all have to adjust how we ask questions. For instance, if I post a question and just ask for an answer, somone might question my motives, even though I was just curious. However, if I show that I've tried to Google the subject and learn on my own or if I rephrase it and ask for good references, tutorials, hints, or a nod in the right direction for this particular topic, people would probably come out of the woodwork to help me. It's not that we believe you are dishonest. It's just that there are enough cheaters out there that it is necessary to have rules in place to deter them. So, please stick around and ask questions, and learn all you can. There ar some good programmers here who will probably help you all the can if you also put in the effort. |
|
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 211
Rep Power: 3
![]() |
I'm sorry I didn't mean to chase you off of the forum. This is a good place for people to get questions answered, both easy and complex.
However, multithreading, is not a beginner's topic, and I meant to start with something simpler, such as learning to sort data first, or learn to get the list of numbers from the user, or some other task, closer to what you're used to doing. Additionally there's (generally) not a problem with discussing school work, as long as it's a discussion or a question. Quite often though people come looking for someone else to do the work, rather than learning on their own. -MBirchmeier <edit> I missed alc's second post, and he sums it up much better than I did. </edit> Last edited by MBirchmeier; Jan 5th, 2006 at 2:34 PM. Reason: *response to alcdotcom's post |
|
|
|
|
|
#9 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
If you haven't done much programming before, yes, this is a bad place to start. Threading ain't easy. Pick up a C# book and learn the basics first.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|