Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 5th, 2006, 12:02 PM   #1
punter
Newbie
 
Join Date: Jan 2006
Posts: 2
Rep Power: 0 punter is on a distinguished road
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...
punter is offline   Reply With Quote
Old Jan 5th, 2006, 12:34 PM   #2
MBirchmeier
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 211
Rep Power: 3 MBirchmeier is on a distinguished road
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
MBirchmeier is offline   Reply With Quote
Old Jan 5th, 2006, 12:43 PM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Quote:
i was thrown this question yesterday from a friend of mine..
Is your "friend" the teacher/professor?
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jan 5th, 2006, 12:54 PM   #4
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 642
Rep Power: 4 Jessehk is on a distinguished road
Quote:
Originally Posted by Infinite Recursion
Is your "friend" the teacher/professor?

Hehe
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Jan 5th, 2006, 1:48 PM   #5
punter
Newbie
 
Join Date: Jan 2006
Posts: 2
Rep Power: 0 punter is on a distinguished road
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:
Are you just talking about using different threads to compute the array or actually using different computers?
... firstly, thanks for some valuable input and this leads me to somewhere. Yes, i am talking about using arrays.
Thank you all anyhow.
punter is offline   Reply With Quote
Old Jan 5th, 2006, 2:08 PM   #6
alcdotcom
Programmer
 
Join Date: Jan 2006
Location: Dallas, TX
Posts: 49
Rep Power: 0 alcdotcom is on a distinguished road
Quote:
Originally Posted by MBirchmeier
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.
Quote:
Originally Posted by punter
...also, noted that this isnt the place for newbies. I guess an early end to my venture on programming forums.
I'm fairly certain that when he said "this probably isn't the place to start" he was talking about this problem, not this forum.
alcdotcom is offline   Reply With Quote
Old Jan 5th, 2006, 2:31 PM   #7
alcdotcom
Programmer
 
Join Date: Jan 2006
Location: Dallas, TX
Posts: 49
Rep Power: 0 alcdotcom is on a distinguished road
Quote:
Originally Posted by punter
but i guess people like me are viewed here as asking these questions to pass their term papers or whatever.
If you knew how often this happened, you might not be offended. 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.
alcdotcom is offline   Reply With Quote
Old Jan 5th, 2006, 2:32 PM   #8
MBirchmeier
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 211
Rep Power: 3 MBirchmeier is on a distinguished road
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
MBirchmeier is offline   Reply With Quote
Old Jan 5th, 2006, 4:04 PM   #9
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:56 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC